]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: use hash_ops with destructor that closes JournalFile
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 14:57:21 +0000 (23:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 00:57:19 +0000 (09:57 +0900)
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-file.h
src/libsystemd/sd-journal/sd-journal.c

index 9d953793a0d968e98d9ae583f9b00ee701f16798..30a5c716a835b1adf50c5be7407a37a44669e0c7 100644 (file)
 #  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:
index 4096f05783e8b18cd7b802a8190c3ccdc3e853d6..669c0661562acd33508775773b1eac74669abe76 100644 (file)
@@ -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,
index 3b1f060565a7cea964fdcb0f3262ca135e3dc39d..b6d3a7f627756e1abfde509082d7a7229de88831 100644 (file)
@@ -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);