mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
mmap-cache: ref/unref MMapCache in fd add/free
Preparatory commit; callers manually ref/unref MMapCaches alongside MMapFileDescriptor add/frees, when the latter should be sufficient. A subsequent commit will drop some of those manual MMapCache reference hoop-jumping, leaving the lifecycle bound to MMapFileDescriptors.
This commit is contained in:
parent
f333ed27fa
commit
fd9ac6c307
@ -560,14 +560,14 @@ MMapFileDescriptor* mmap_cache_add_fd(MMapCache *m, int fd, int prot) {
|
|||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
f->cache = m;
|
|
||||||
f->fd = fd;
|
|
||||||
f->prot = prot;
|
|
||||||
|
|
||||||
r = hashmap_put(m->fds, FD_TO_PTR(fd), f);
|
r = hashmap_put(m->fds, FD_TO_PTR(fd), f);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return mfree(f);
|
return mfree(f);
|
||||||
|
|
||||||
|
f->cache = mmap_cache_ref(m);
|
||||||
|
f->fd = fd;
|
||||||
|
f->prot = prot;
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,8 +584,10 @@ void mmap_cache_fd_free(MMapFileDescriptor *f) {
|
|||||||
while (f->windows)
|
while (f->windows)
|
||||||
window_free(f->windows);
|
window_free(f->windows);
|
||||||
|
|
||||||
if (f->cache)
|
if (f->cache) {
|
||||||
assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd)));
|
assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd)));
|
||||||
|
f->cache = mmap_cache_unref(f->cache);
|
||||||
|
}
|
||||||
|
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user