All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
To: ceph-devel@vger.kernel.org
Cc: Danny Al-Gaaf <dalgaaf@suse.de>, Sage Weil <sage@inktank.com>
Subject: [PATCH 1/6] common/fiemap.cc: fix realloc memory leak
Date: Fri,  8 Feb 2013 17:24:58 +0100	[thread overview]
Message-ID: <1360340703-7170-2-git-send-email-danny.al-gaaf@bisect.de> (raw)
In-Reply-To: <1360340703-7170-1-git-send-email-danny.al-gaaf@bisect.de>

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 | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/common/fiemap.cc b/src/common/fiemap.cc
index 0df12d6..a1d5fbe 100644
--- a/src/common/fiemap.cc
+++ b/src/common/fiemap.cc
@@ -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);
-- 
1.8.1.2


  reply	other threads:[~2013-02-08 16:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 16:24 [PATCH 0/6] Fix some memory leaks in Ceph Danny Al-Gaaf
2013-02-08 16:24 ` Danny Al-Gaaf [this message]
2013-02-08 16:24 ` [PATCH 2/6] os/FileStore.cc: fix realloc memory leak in error case Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 3/6] rgw/rgw_xml.cc: " Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 4/6] wireshark: fix some memory leaks Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 5/6] SyntheticClient.cc: fix some memory leaks in the error handling Danny Al-Gaaf
2013-02-08 17:47   ` Danny Al-Gaaf
2013-02-08 17:52     ` [PATCH v2 " Danny Al-Gaaf
2013-02-10  6:04   ` [PATCH " Sage Weil
2013-02-10  8:43     ` Danny Al-Gaaf
2013-02-11  2:07       ` Sage Weil
2013-02-08 16:25 ` [PATCH 6/6] rgw/rgw_rest.cc: fix 4K memory leak Danny Al-Gaaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360340703-7170-2-git-send-email-danny.al-gaaf@bisect.de \
    --to=danny.al-gaaf@bisect.de \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dalgaaf@suse.de \
    --cc=sage@inktank.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.