From: Vito Caputo Date: Thu, 25 Nov 2021 23:01:38 +0000 (-0800) Subject: mmap-cache: ref/unref MMapCache in fd add/free X-Git-Tag: v250-rc1~27^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd9ac6c3078ba1c0037c10bdb0412d84e0b76966;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/libsystemd/sd-journal/mmap-cache.c b/src/libsystemd/sd-journal/mmap-cache.c index faf05c55073..4ecaaf23887 100644 --- a/src/libsystemd/sd-journal/mmap-cache.c +++ b/src/libsystemd/sd-journal/mmap-cache.c @@ -560,14 +560,14 @@ MMapFileDescriptor* mmap_cache_add_fd(MMapCache *m, int fd, int prot) { if (!f) return NULL; - f->cache = m; - f->fd = fd; - f->prot = prot; - r = hashmap_put(m->fds, FD_TO_PTR(fd), f); if (r < 0) return mfree(f); + f->cache = mmap_cache_ref(m); + f->fd = fd; + f->prot = prot; + return f; } @@ -584,8 +584,10 @@ void mmap_cache_fd_free(MMapFileDescriptor *f) { while (f->windows) window_free(f->windows); - if (f->cache) + if (f->cache) { assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd))); + f->cache = mmap_cache_unref(f->cache); + } free(f); }