From fd9ac6c3078ba1c0037c10bdb0412d84e0b76966 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 25 Nov 2021 15:01:38 -0800 Subject: [PATCH] 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. --- src/libsystemd/sd-journal/mmap-cache.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libsystemd/sd-journal/mmap-cache.c b/src/libsystemd/sd-journal/mmap-cache.c index faf05c5507..4ecaaf2388 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); } -- 2.25.1