]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix memory leak in Backtrace::print()
authorLi Wang <liwang@ubuntukylin.com>
Wed, 30 Oct 2013 08:18:10 +0000 (16:18 +0800)
committerSage Weil <sage@inktank.com>
Wed, 30 Oct 2013 16:02:43 +0000 (09:02 -0700)
Free already allocated memory if short of memory

Signed-off-by: Li Wang <liwang@ubuntukylin.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/common/BackTrace.cc

index 6cace65ab6d4339dac7fc16d5b27ad5651f62b83..886ed6a16d4b671513f16039e300bde8905def02 100644 (file)
@@ -36,8 +36,10 @@ void BackTrace::print(std::ostream& out)
     if (begin && end) {
       int len = end - begin;
       char *foo = (char *)malloc(len+1);
-      if (!foo)
-        return;
+      if (!foo) {
+       free(function);
+       return;
+      }
       memcpy(foo, begin, len);
       foo[len] = 0;