From: Danny Al-Gaaf Date: Fri, 8 Feb 2013 15:57:20 +0000 (+0100) Subject: rgw/rgw_xml.cc: fix realloc memory leak in error case X-Git-Tag: v0.56.4~65^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f19d228c6a49222659c769099aaa4e755b80331d;p=ceph.git rgw/rgw_xml.cc: fix realloc memory leak in error case 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 (cherry picked from commit d48cc789ea075ba2745754035640ada4131b2119) --- diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 4347b06115c6..eee69d026ba7 100644 --- a/src/rgw/rgw_xml.cc +++ b/src/rgw/rgw_xml.cc @@ -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;