diff mbox

[5/6] SyntheticClient.cc: fix some memory leaks in the error handling

Message ID 1360340703-7170-6-git-send-email-danny.al-gaaf@bisect.de (mailing list archive)
State New, archived
Headers show

Commit Message

Danny Al-Gaaf Feb. 8, 2013, 4:25 p.m. UTC
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 <danny.al-gaaf@bisect.de>
---
 src/client/SyntheticClient.cc | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Danny Al-Gaaf Feb. 8, 2013, 5:47 p.m. UTC | #1
Am 08.02.2013 17:25, schrieb Danny Al-Gaaf:
> 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 <danny.al-gaaf@bisect.de>

Sorry, wrong patch version with a bug. I'll send a new version of this
patch.

Danny
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sage Weil Feb. 10, 2013, 6:04 a.m. UTC | #2
On Fri, 8 Feb 2013, Danny Al-Gaaf wrote:
> 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 <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) {
> +    return fd;
> +    delete[] buf;

oops, wrong order...

> +  }
>  
>    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) {
> +    return fd;
> +    delete[] buf;

here too!

> +  }
>  
>    utime_t from = ceph_clock_now(g_ceph_context);
>    utime_t start = from;
> -- 
> 1.8.1.2
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Danny Al-Gaaf Feb. 10, 2013, 8:43 a.m. UTC | #3
Am 10.02.2013 07:04, schrieb Sage Weil:
> On Fri, 8 Feb 2013, Danny Al-Gaaf wrote:
[...]
>>    //dout(5) << "SyntheticClient::write_fd: writing to fd " << fd << dendl;
>> -  if (fd < 0) return fd;
>> +  if (fd < 0) {
>> +    return fd;
>> +    delete[] buf;
> 
> oops, wrong order...

I know, that's why I've send another fixed version of this patch to the
list the same day:
http://thread.gmane.org/gmane.comp.file-systems.ceph.devel/12969/focus=12985

Danny

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sage Weil Feb. 11, 2013, 2:07 a.m. UTC | #4
On Sun, 10 Feb 2013, Danny Al-Gaaf wrote:
> Am 10.02.2013 07:04, schrieb Sage Weil:
> > On Fri, 8 Feb 2013, Danny Al-Gaaf wrote:
> [...]
> >>    //dout(5) << "SyntheticClient::write_fd: writing to fd " << fd << dendl;
> >> -  if (fd < 0) return fd;
> >> +  if (fd < 0) {
> >> +    return fd;
> >> +    delete[] buf;
> > 
> > oops, wrong order...
> 
> I know, that's why I've send another fixed version of this patch to the
> list the same day:
> http://thread.gmane.org/gmane.comp.file-systems.ceph.devel/12969/focus=12985

Oops, I see it now, sorry :)

I merged the memleaks branch.  The cppcheck-clang one is coming up with 
build errors tho:

	http://ceph.com/gitbuilder.cgi

Thanks!
sage
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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; 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) {
+    return fd;
+    delete[] buf;
+  }
 
   utime_t from = ceph_clock_now(g_ceph_context);
   utime_t start = from;