Free already allocated memory if short of memory

Signed-off-by: Li Wang <liw...@ubuntukylin.com>
---
 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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to