]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/rgw_xml.cc: fix realloc memory leak in error case
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 8 Feb 2013 15:57:20 +0000 (16:57 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Sat, 16 Feb 2013 17:38:57 +0000 (18:38 +0100)
Fix error from cppcheck:

[src/rgw/rgw_xml.cc:212]: (error) Common realloc mistake: 'buf'
  nulled but not freed upon failure

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
(cherry picked from commit d48cc789ea075ba2745754035640ada4131b2119)

src/rgw/rgw_xml.cc

index 4347b06115c63eab842eaf48f9c3e5502c7c9d2d..eee69d026ba78fa034d67df88470bd4eb3da5f58 100644 (file)
@@ -209,9 +209,16 @@ bool RGWXMLParser::init()
 bool RGWXMLParser::parse(const char *_buf, int len, int done)
 {
   int pos = buf_len;
-  buf = (char *)realloc(buf, buf_len + len);
-  if (!buf)
+  char *tmp_buf;
+  tmp_buf = (char *)realloc(buf, buf_len + len);
+  if (tmp_buf == NULL){
+    free(buf);
+    buf = NULL;
     return false;
+  } else {
+    buf = tmp_buf;
+  }
+
   memcpy(&buf[buf_len], _buf, len);
   buf_len += len;