From patchwork Fri Feb 8 16:25:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danny Al-Gaaf X-Patchwork-Id: 2116911 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 5187D40B0D for ; Fri, 8 Feb 2013 16:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946760Ab3BHQZM (ORCPT ); Fri, 8 Feb 2013 11:25:12 -0500 Received: from wp188.webpack.hosteurope.de ([80.237.132.195]:39602 "EHLO wp188.webpack.hosteurope.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946758Ab3BHQZL (ORCPT ); Fri, 8 Feb 2013 11:25:11 -0500 Received: from charybdis-ext.suse.de ([195.135.221.2] helo=darkangel.suse.de); authenticated by wp188.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) id 1U3ql6-0006c0-Ur; Fri, 08 Feb 2013 17:25:05 +0100 From: Danny Al-Gaaf To: ceph-devel@vger.kernel.org Cc: Danny Al-Gaaf , Sage Weil Subject: [PATCH 3/6] rgw/rgw_xml.cc: fix realloc memory leak in error case Date: Fri, 8 Feb 2013 17:25:00 +0100 Message-Id: <1360340703-7170-4-git-send-email-danny.al-gaaf@bisect.de> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360340703-7170-1-git-send-email-danny.al-gaaf@bisect.de> References: <1360340703-7170-1-git-send-email-danny.al-gaaf@bisect.de> X-bounce-key: webpack.hosteurope.de; danny.al-gaaf@bisect.de; 1360340711; 326f4555; Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 --- src/rgw/rgw_xml.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 4347b06..eee69d0 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;