mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
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:
parent
c92a0f5525
commit
d48cc789ea
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user