Skip to contentSkip to conversation

Fix memory leak in Backtrace::print()

PATCH New Li Wang 1 participant 1 message Oct 30, 2013

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 Fix memory leak in Backtrace::print()

Free already allocated memory if short of memory

---
 src/common/BackTrace.cc |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/common/BackTrace.cc +4 -2
index 6cace65..886ed6a 100644
@@ -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;
 
Signature · 1 line
1.7.9.5