From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17497 invoked by alias); 8 Jul 2008 06:57:09 -0000 Received: (qmail 17479 invoked by uid 22791); 8 Jul 2008 06:57:08 -0000 X-Spam-Check-By: sourceware.org Received: from ti-out-0910.google.com (HELO ti-out-0910.google.com) (209.85.142.186) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 08 Jul 2008 06:56:51 +0000 Received: by ti-out-0910.google.com with SMTP id d10so644686tib.12 for ; Mon, 07 Jul 2008 23:56:48 -0700 (PDT) Received: by 10.110.46.3 with SMTP id t3mr3306980tit.33.1215500208622; Mon, 07 Jul 2008 23:56:48 -0700 (PDT) Received: by 10.110.109.4 with HTTP; Mon, 7 Jul 2008 23:56:48 -0700 (PDT) Message-ID: Date: Tue, 08 Jul 2008 06:57:00 -0000 From: teawater To: gdb-patches@sourceware.org Subject: [patch]: Fix memory leak of symtab.c MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-07/txt/msg00112.txt.bz2 symtab.c has a memory leek in function expand_line_sal. struct block **blocks and int *filter are xmalloc at line 4459 and 4460. There are returns at the end of this function without calling xfree. And these variables is just used in this function. So I change them to "alloca". This patch is for the GDB cvs version. 2008-06-21 Hui Zhu * symtab.c (expand_line_sal): Fix a memory leak. --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4456,8 +4456,8 @@ expand_line_sal (struct symtab_and_line blocks -- for each PC found above we see if there are other PCs that are in the same block. If yes, the other PCs are filtered out. */ - filter = xmalloc (ret.nelts * sizeof (int)); - blocks = xmalloc (ret.nelts * sizeof (struct block *)); + filter = alloca (ret.nelts * sizeof (int)); + blocks = alloca (ret.nelts * sizeof (struct block *)); for (i = 0; i < ret.nelts; ++i) { filter[i] = 1;