From patchwork Wed Oct 30 08:18:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 3113481 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8403A9F3E2 for ; Wed, 30 Oct 2013 08:18:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 823AA201FB for ; Wed, 30 Oct 2013 08:18:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95DF620154 for ; Wed, 30 Oct 2013 08:18:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752137Ab3J3ISX (ORCPT ); Wed, 30 Oct 2013 04:18:23 -0400 Received: from m199-177.yeah.net ([123.58.177.199]:46877 "EHLO m199-177.yeah.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751702Ab3J3ISW (ORCPT ); Wed, 30 Oct 2013 04:18:22 -0400 Received: from localhost.localdomain (unknown [222.240.177.34]) by m199-177.yeah.net (HMail) with ESMTPA id 6A5AB1101146; Wed, 30 Oct 2013 16:18:19 +0800 (CST) From: Li Wang To: Cc: Sage Weil , Li Wang Subject: [PATCH] Fix memory leak in Backtrace::print() Date: Wed, 30 Oct 2013 16:18:10 +0800 Message-Id: <1383121090-18727-1-git-send-email-liwang@ubuntukylin.com> X-Mailer: git-send-email 1.7.9.5 X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQUhDVUpMQkJCTU9CS09MQ05KTVdZCQ4XHghZQV koKz0kKzooKCQyNSQzPjo*PilBTlVJTk1ANiMkIj4oJDI1JDM#Oj8#KUFLVUhPSUArLykkNTQkMj UkMz46Pz4pQUlVQ05DQDg0LjUvKSIkODVBS1VJTUNAKT48MjQ1JDooMjpBSFVPT01AKyk0LTI1OD 4kMy41OjVBQlVCSk5APyI1OjYyOCQyKyQ1NCQyNSQzPjo*PilBS1VMQ0JAPzAyNiQ1NDU#QUtVS0 ApPjo3JDIrJDI1JCk5NyQyNSQzPjo*PilBTFVLS0NANi43LzIkKTgrLyQ*Mj09Pik#NS8kMjUkMz 46Pz4pQU9VS0tJQDIrJEhLJDYyNS4vPiQ4NS8kSyROS0FLVUtAMiskSiQzNC4pJDg1LyRLJEpLS0 FLVUtAMiskSiQ2MjUuLz4kODUvJEskSktBS1VLQDIrJE4kNjI1Li8#JDg1LyRLJEpLQUtVS0AyKy QvND86IiQ4NS8kSyRKS0tBS1VMSk1AKC45JD5BSlVOTkA9NSQoLjkkPjUsNCk*KCQzNzEkSktLSU tKQUtVSUNAPTUkPSk#PiQzNzEkS0xLTktPQUpVTE5ZBg++ X-HM-Sender-Digest: e1kSHx4VD1lBWUc6MQg6Cjo4LDo4EDorKjhIOj4qOkMwCjFVSlVKSENI SklKS0JCTkJLVTMWGhIXVRcSDBoVHDsOGQ4VDw4QAhcSFVUYFBZFWVdZDB4ZWUEdGhcIHldZCAFZ QUpISko3V1kSC1lBWUlJSVVJT0tVSkxMVUhPWQY+ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Free already allocated memory if short of memory Signed-off-by: Li Wang --- 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;