Skip to contentSkip to conversation

Ceph: Fix memory leak in chain_flistxattr()

PATCH New Li Wang 1 participant 1 message Nov 7, 2013

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 Ceph: Fix memory leak in chain_flistxattr()

Free allocated memory before return.

---
 src/os/chain_xattr.cc |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
src/os/chain_xattr.cc +9 -5
index 8ca8156..c020c9d 100644
@@ -388,6 +388,10 @@ done:
 
 int chain_flistxattr(int fd, char *names, size_t len) {
   int r;
+  char *p;
+  const char * end;
+  char *dest;
+  char *dest_end;
 
   if (!len)
     return sys_flistxattr(fd, names, len) * 2;
@@ -403,12 +407,12 @@ int chain_flistxattr(int fd, char *names, size_t len) {
 
   r = sys_flistxattr(fd, full_buf, total_len);
   if (r < 0)
-    return r;
+    goto done;
 
-  char *p = full_buf;
-  const char *end = full_buf + r;
-  char *dest = names;
-  char *dest_end = names + len;
+  p = full_buf;
+  end = full_buf + r;
+  dest = names;
+  dest_end = names + len;
 
   while (p < end) {
     char name[CHAIN_XATTR_MAX_NAME_LEN * 2 + 16];
Signature · 1 line
1.7.9.5