All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
To: ceph-devel@vger.kernel.org
Cc: Danny Al-Gaaf <dalgaaf@suse.de>, Sage Weil <sage@inktank.com>
Subject: [PATCH v2 5/6] SyntheticClient.cc: fix some memory leaks in the error handling
Date: Fri,  8 Feb 2013 18:52:20 +0100	[thread overview]
Message-ID: <1360345940-8481-1-git-send-email-danny.al-gaaf@bisect.de> (raw)
In-Reply-To: <51153A4F.8030107@bisect.de>

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

---
v2: - fix order in two cases 

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
---
 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) {
+    delete[] buf;
+    return fd;
+  }
 
   for (unsigned i=0; i<chunks; i++) {
     if (time_to_stop()) {
@@ -2087,7 +2093,10 @@ int SyntheticClient::read_file(const std::string& fn, int size,
 
   int fd = client->open(fn.c_str(), O_RDONLY);
   dout(5) << "reading from " << 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;
-- 
1.8.1.2


  reply	other threads:[~2013-02-08 17:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 16:24 [PATCH 0/6] Fix some memory leaks in Ceph Danny Al-Gaaf
2013-02-08 16:24 ` [PATCH 1/6] common/fiemap.cc: fix realloc memory leak Danny Al-Gaaf
2013-02-08 16:24 ` [PATCH 2/6] os/FileStore.cc: fix realloc memory leak in error case Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 3/6] rgw/rgw_xml.cc: " Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 4/6] wireshark: fix some memory leaks Danny Al-Gaaf
2013-02-08 16:25 ` [PATCH 5/6] SyntheticClient.cc: fix some memory leaks in the error handling Danny Al-Gaaf
2013-02-08 17:47   ` Danny Al-Gaaf
2013-02-08 17:52     ` Danny Al-Gaaf [this message]
2013-02-10  6:04   ` Sage Weil
2013-02-10  8:43     ` Danny Al-Gaaf
2013-02-11  2:07       ` Sage Weil
2013-02-08 16:25 ` [PATCH 6/6] rgw/rgw_rest.cc: fix 4K memory leak Danny Al-Gaaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360345940-8481-1-git-send-email-danny.al-gaaf@bisect.de \
    --to=danny.al-gaaf@bisect.de \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dalgaaf@suse.de \
    --cc=sage@inktank.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.