From patchwork Fri Feb 8 16:25:02 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: 2116901 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 37FB640106 for ; Fri, 8 Feb 2013 16:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946759Ab3BHQZL (ORCPT ); Fri, 8 Feb 2013 11:25:11 -0500 Received: from wp188.webpack.hosteurope.de ([80.237.132.195]:39599 "EHLO wp188.webpack.hosteurope.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946757Ab3BHQZL (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 1U3ql7-0006c0-6K; 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 5/6] SyntheticClient.cc: fix some memory leaks in the error handling Date: Fri, 8 Feb 2013 17:25:02 +0100 Message-Id: <1360340703-7170-6-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; 1360340710; 73141e6a; Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Fix some memory leaks in case of error handling due to failed client->open() calls. Error from cppcheck was: [src/client/SyntheticClient.cc:1980]: (error) Memory leak: buf [src/client/SyntheticClient.cc:2040]: (error) Memory leak: buf [src/client/SyntheticClient.cc:2090]: (error) Memory leak: buf Signed-off-by: Danny Al-Gaaf --- src/client/SyntheticClient.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index b2a936f..0da8bed 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1977,7 +1977,10 @@ int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size i int fd = client->open(fn.c_str(), O_RDWR|O_CREAT); dout(5) << "writing to " << fn << " fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + delete[] buf; + return fd; + } utime_t from = ceph_clock_now(g_ceph_context); utime_t start = from; @@ -2037,7 +2040,10 @@ int SyntheticClient::write_fd(int fd, int size, int wrsize) // size is in MB, uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)wrsize; //dout(5) << "SyntheticClient::write_fd: writing to fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + return fd; + delete[] buf; + } for (unsigned i=0; iopen(fn.c_str(), O_RDONLY); dout(5) << "reading from " << fn << " fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + return fd; + delete[] buf; + } utime_t from = ceph_clock_now(g_ceph_context); utime_t start = from;