From patchwork Tue May 27 10:57:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 1166 Received: (qmail 23244 invoked by alias); 27 May 2014 10:57:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 23220 invoked by uid 89); 27 May 2014 10:57:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-gw1-out.broadcom.com Received: from mail-gw1-out.broadcom.com (HELO mail-gw1-out.broadcom.com) (216.31.210.62) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 May 2014 10:57:47 +0000 Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw1-out.broadcom.com with ESMTP; 27 May 2014 04:03:24 -0700 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 27 May 2014 03:57:45 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Tue, 27 May 2014 03:57:45 -0700 Received: from xl-cam-21.broadcom.com (xl-cam-21.cam.broadcom.com [10.177.132.81]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 278A49F9F7; Tue, 27 May 2014 03:57:45 -0700 (PDT) Received: by xl-cam-21.broadcom.com (Postfix, from userid 15136) id 753252CE899E; Tue, 27 May 2014 11:57:44 +0100 (BST) From: Andrew Burgess To: CC: , Andrew Burgess Subject: [PATCH] Delete temporary string within demangler even in failure cases. Date: Tue, 27 May 2014 11:57:33 +0100 Message-ID: <1401188253-15214-1-git-send-email-aburgess@broadcom.com> MIME-Version: 1.0 X-IsSubscribed: yes Spotted that a call to demangle_template might allocate storage within a temporary string even if the call to demangle_template eventually returns failure. This will never cause the demangler to crash, but does leak memory, as a result I've not added any tests for this. Calling string_delete is safe, even if nothing is allocated into the string, the string is initialised with string_init, so we know the internal pointers are NULL. I don't have gcc write privilages, so if this is approved could someone please commit for me. Thanks, Andrew libiberty/ChangeLog * cplus-dem.c (do_type): Call string_delete even if the call to demangle_template fails. --- libiberty/cplus-dem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c index e948487..1c713aa 100644 --- a/libiberty/cplus-dem.c +++ b/libiberty/cplus-dem.c @@ -3656,7 +3656,10 @@ do_type (struct work_stuff *work, const char **mangled, string *result) string_delete (&temp); } else - break; + { + string_delete (&temp); + break; + } } else if (**mangled == 'Q') {