]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/fiemap.cc: fix realloc memory leak
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 8 Feb 2013 15:49:36 +0000 (16:49 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Sun, 10 Feb 2013 09:05:05 +0000 (10:05 +0100)
Fix error from cppcheck:

[src/common/fiemap.cc:73]: (error) Common realloc mistake: 'fiemap'
  nulled but not freed upon failure

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/common/fiemap.cc

index 0df12d6e8fd1e2ac11fe1864261ef11464d1efe1..a1d5fbe9396ad3075014badb1aedbdb1bbd9b7f9 100644 (file)
@@ -40,6 +40,7 @@
 struct fiemap *read_fiemap(int fd)
 {
   struct fiemap *fiemap;
+  struct fiemap *_realloc_fiemap = NULL;
   int extents_size;
   int r;
 
@@ -62,18 +63,20 @@ struct fiemap *read_fiemap(int fd)
   }
 
   if (!fiemap->fm_mapped_extents) {
-    free(fiemap);
-    return NULL;
+    goto done_err;
   }
 
   /* Read in the extents */
   extents_size = sizeof(struct fiemap_extent) * (fiemap->fm_mapped_extents);
 
   /* Resize fiemap to allow us to read in the extents */
-  if ((fiemap = (struct fiemap*)realloc(fiemap,sizeof(struct fiemap) +
+
+  if ((_realloc_fiemap = (struct fiemap*)realloc(fiemap,sizeof(struct fiemap) +
                                         extents_size)) == NULL) {
     fprintf(stderr, "Out of memory allocating fiemap\n");
     goto done_err;
+  } else {
+    fiemap = _realloc_fiemap;
   }
 
   memset(fiemap->fm_extents, 0, extents_size);