Fix bug 3006812: ensure exif cache is initialized even when all files are unreadable.
authorLaurent Monin <geeqie@norz.org>
Thu, 16 Dec 2010 21:26:36 +0000 (22:26 +0100)
committerVladimir Nadvornik <nadvornik@suse.cz>
Tue, 27 Sep 2011 12:19:02 +0000 (14:19 +0200)
Add a new function exif_init_cache() and call it at top of exif_read_fd(),
the issue was caused by a return NULL on unreadable file, before initializinf exif_cache
and when exif_free_fd() is called, file_cache_put() was called on invalid cache.

src/exif-common.c

index 49b31f2..f87d141 100644 (file)
@@ -636,14 +636,20 @@ void exif_release_cb(FileData *fd)
        fd->exif = NULL;
 }
 
+void exif_init_cache(void)
+{
+       assert(!exif_cache);
+       exif_cache = file_cache_new(exif_release_cb, 4);
+}
+
 ExifData *exif_read_fd(FileData *fd)
 {
        gchar *sidecar_path;
+       
+       if (!exif_cache) exif_init_cache();
 
        if (!fd || !is_readable_file(fd->path)) return NULL;
        
-       if (!exif_cache) exif_cache = file_cache_new(exif_release_cb, 4);
-       
        if (file_cache_get(exif_cache, fd)) return fd->exif;
        
        /* CACHE_TYPE_XMP_METADATA file should exist only if the metadata are