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)
committerKlaus Ethgen <Klaus@Ethgen.de>
Sat, 3 Sep 2011 19:40:07 +0000 (20:40 +0100)
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 ef7476b..5664cb4 100644 (file)
@@ -607,14 +607,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