From: Yu Watanabe Date: Sat, 12 Apr 2025 14:57:21 +0000 (+0900) Subject: sd-journal: use hash_ops with destructor that closes JournalFile X-Git-Tag: v258-rc1~813^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8eb4ce4118a2cbc80a52531b9fb0a6042774e45e;p=thirdparty%2Fsystemd.git sd-journal: use hash_ops with destructor that closes JournalFile --- diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 9d953793a0d..30a5c716a83 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -92,6 +92,11 @@ # pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif +DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + journal_file_hash_ops_by_path, + char, path_hash_func, path_compare, + JournalFile, journal_file_close); + static int mmap_prot_from_open_flags(int flags) { switch (flags & O_ACCMODE) { case O_RDONLY: diff --git a/src/libsystemd/sd-journal/journal-file.h b/src/libsystemd/sd-journal/journal-file.h index 4096f05783e..669c0661562 100644 --- a/src/libsystemd/sd-journal/journal-file.h +++ b/src/libsystemd/sd-journal/journal-file.h @@ -145,6 +145,8 @@ typedef struct { uint64_t hash; } EntryItem; +extern const struct hash_ops journal_file_hash_ops_by_path; + int journal_file_open( int fd, const char *fname, diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 3b1f060565a..b6d3a7f6277 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2296,7 +2296,7 @@ static sd_journal *journal_new(int flags, const char *path, const char *namespac return NULL; } - j->files = ordered_hashmap_new(&path_hash_ops); + j->files = ordered_hashmap_new(&journal_file_hash_ops_by_path); if (!j->files) return NULL; @@ -2548,7 +2548,7 @@ _public_ void sd_journal_close(sd_journal *j) { if (j->mmap) mmap_cache_stats_log_debug(j->mmap); - ordered_hashmap_free_with_destructor(j->files, journal_file_close); + ordered_hashmap_free(j->files); iterated_cache_free(j->files_cache); hashmap_free(j->directories_by_path);