Fix resource leak
[platform/core/appfw/xdgmime.git] / xdgmime / src / xdgmimecache.c
index 1e99b3e..ddcb90c 100644 (file)
@@ -124,7 +124,7 @@ _xdg_mime_cache_new_from_file (const char *file_name)
 
   if (fd < 0)
     return NULL;
-  
+
   if (fstat (fd, &st) < 0 || st.st_size < 4)
     goto done;
 
@@ -143,8 +143,15 @@ _xdg_mime_cache_new_from_file (const char *file_name)
 
       goto done;
     }
-  
+
   cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache));
+  if (cache == NULL)
+    {
+      munmap (buffer, st.st_size);
+
+      goto done;
+    }
+
   cache->minor = minor;
   cache->ref_count = 1;
   cache->buffer = buffer;