if (!f)
return NULL;
- if (f->mmap && f->cache_fd)
+ if (f->cache_fd)
mmap_cache_fd_free(f->cache_fd);
if (f->close_fd)
safe_close(f->fd);
free(f->path);
- mmap_cache_unref(f->mmap);
-
ordered_hashmap_free_free(f->chain_cache);
#if HAVE_COMPRESSION
JournalFile **ret) {
bool newly_created = false;
+ MMapCache *m = mmap_cache;
JournalFile *f;
void *h;
int r;
}
}
- if (mmap_cache)
- f->mmap = mmap_cache_ref(mmap_cache);
- else {
- f->mmap = mmap_cache_new();
- if (!f->mmap) {
+ if (!m) {
+ m = mmap_cache_new();
+ if (!m) {
r = -ENOMEM;
goto fail;
}
goto fail;
}
- f->cache_fd = mmap_cache_add_fd(f->mmap, f->fd, prot_from_flags(flags));
+ /* On success this incs refcnt on *m, which mmap_cache_fd_free() will dec. */
+ f->cache_fd = mmap_cache_add_fd(m, f->fd, prot_from_flags(flags));
if (!f->cache_fd) {
r = -ENOMEM;
goto fail;
}
+ /* If we created *m just for this file, unref *m so only f->cache_fd's ref remains */
+ if (!mmap_cache)
+ (void) mmap_cache_unref(m);
+
r = journal_file_fstat(f);
if (r < 0)
goto fail;