From: Danny Al-Gaaf Date: Mon, 13 May 2013 12:15:04 +0000 (+0200) Subject: tools/ceph.cc: cleanup memory allocated for 'buf' X-Git-Tag: v0.63~29^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eac545e12cff6203bc46e77142bb1be2f466bf9c;p=ceph.git 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 --- 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; }