From eac545e12cff6203bc46e77142bb1be2f466bf9c Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Mon, 13 May 2013 14:15:04 +0200 Subject: [PATCH] tools/ceph.cc: cleanup memory allocated for 'buf' 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 --- src/tools/ceph.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tools/ceph.cc b/src/tools/ceph.cc index fd4dbb17d7b2..b0cf91a53417 100644 --- a/src/tools/ceph.cc +++ b/src/tools/ceph.cc @@ -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; } -- 2.47.3