]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph.cc: cleanup memory allocated for 'buf'
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Mon, 13 May 2013 12:15:04 +0000 (14:15 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 14 May 2013 16:39:31 +0000 (18:39 +0200)
CID 717123 (#1-2 of 2): Resource leak (RESOURCE_LEAK)
  leaked_storage: Variable "buf" going out of scope leaks the storage
  it points to.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/tools/ceph.cc

index fd4dbb17d7b2969e79f31bb91aaa1b6fa4e4e031..b0cf91a53417a999e4954a3f6549e51095c9a2c3 100644 (file)
@@ -232,11 +232,11 @@ int do_admin_socket(string path, string cmd)
   if (connect(fd, (struct sockaddr *) &address, 
              sizeof(struct sockaddr_un)) != 0) {
     cerr << "connect to " << path << " failed with " << cpp_strerror(errno) << std::endl;
-    r = -1;
-    goto out;
+    ::close(fd);
+    return -1;
   }
   
-  char *buf;
+  char *buf = NULL;
   uint32_t len;
   r = safe_write(fd, cmd.c_str(), cmd.length() + 1);
   if (r < 0) {
@@ -268,6 +268,8 @@ int do_admin_socket(string path, string cmd)
   r = 0;
 
  out:
+  if (buf)
+    delete[] buf;
   ::close(fd);
   return r;
 }