sd-journal: use hash_ops with destructor that closes JournalFile
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user