[PATCH] Fix memory leak in Backtrace::print()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Free already allocated memory if short of memory

Signed-off-by: Li Wang <liwang@xxxxxxxxxxxxxxx>
---
 src/common/BackTrace.cc |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/common/BackTrace.cc b/src/common/BackTrace.cc
index 6cace65..886ed6a 100644
--- a/src/common/BackTrace.cc
+++ b/src/common/BackTrace.cc
@@ -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;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux