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 <danny.al-gaaf@bisect.de>
This commit is contained in:
Danny Al-Gaaf 2013-02-08 16:57:20 +01:00
parent c92a0f5525
commit d48cc789ea

View 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;