From 3e0e566eca5097f546eb5989196722ac6c1f732c Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Fri, 27 Jul 2012 15:03:58 +0200 Subject: [PATCH] fixed bug in cache handling changed files stayed in cache, but they were reported as not found, this caused leaks and crashes bug introduced by change of notification function, commit 78cde6934008f79fe498e4adc64d187b0ed47417 --- src/exif-common.c | 1 + src/filecache.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/exif-common.c b/src/exif-common.c index fbc41997..93a8f8cd 100644 --- a/src/exif-common.c +++ b/src/exif-common.c @@ -652,6 +652,7 @@ ExifData *exif_read_fd(FileData *fd) if (!fd || !is_readable_file(fd->path)) return NULL; if (file_cache_get(exif_cache, fd)) return fd->exif; + g_assert(fd->exif == NULL); /* CACHE_TYPE_XMP_METADATA file should exist only if the metadata are * not writable directly, thus it should contain the most up-to-date version */ diff --git a/src/filecache.c b/src/filecache.c index 4d9710fc..46f083d6 100644 --- a/src/filecache.c +++ b/src/filecache.c @@ -32,6 +32,7 @@ struct _FileCacheEntry { }; static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data); +static void file_cache_remove_fd(FileCacheData *fc, FileData *fd); FileCacheData *file_cache_new(FileCacheReleaseFunc release, gulong max_size) { @@ -67,9 +68,11 @@ gboolean file_cache_get(FileCacheData *fc, FileData *fd) fc->list = g_list_remove_link(fc->list, work); fc->list = g_list_concat(work, fc->list); - if (file_data_check_changed_files(fd)) /* this will eventually remove changed files from cache via file_cache_notify_cb */ + if (file_data_check_changed_files(fd)) { + /* file has been changed, cance entry is no longer valid */ + file_cache_remove_fd(fc, fd); return FALSE; - + } if (debug_file_cache) file_cache_dump(fc); return TRUE; } -- 2.20.1