From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13809 invoked by alias); 21 Oct 2009 23:10:54 -0000 Received: (qmail 13718 invoked by uid 22791); 21 Oct 2009 23:10:51 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Oct 2009 23:10:45 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LNAgqB031719 for ; Wed, 21 Oct 2009 19:10:42 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LNAZg7007648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 21 Oct 2009 19:10:41 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n9LNAYnj003314 for ; Thu, 22 Oct 2009 01:10:34 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id n9LNAYMO003313 for gdb-patches@sourceware.org; Thu, 22 Oct 2009 01:10:34 +0200 Date: Wed, 21 Oct 2009 23:10:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch 2/3] find_separate_debug_file cleanup Message-ID: <20091021231034.GC2658@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) 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: 2009-10/txt/msg00509.txt.bz2 Hi, current code was: * difficult to maintain as a new variable required xfree on many places * was causing memory corruptions due to silently misapplied 3rd party patches as the close code fragments unfortunately match patch context Thanks, Jan gdb/ 2009-10-21 Jan Kratochvil * symfile.c (find_separate_debug_file): Initialize dir, debugfile and canon_name to NULL. Change alloca to xmalloc, newly call xfree for it. New label cleanup_return_debugfile, jump to it from the failure paths. --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1333,11 +1333,10 @@ static char * find_separate_debug_file (struct objfile *objfile) { asection *sect; - char *basename; - char *dir; - char *debugfile; - char *name_copy; - char *canon_name; + char *basename, *name_copy; + char *dir = NULL; + char *debugfile = NULL; + char *canon_name = NULL; bfd_size_type debuglink_size; unsigned long crc32; int i; @@ -1366,7 +1365,7 @@ find_separate_debug_file (struct objfile *objfile) if (basename == NULL) /* There's no separate debug info, hence there's no way we could load it => no warning. */ - return NULL; + goto cleanup_return_debugfile; dir = xstrdup (objfile->name); @@ -1388,24 +1387,19 @@ find_separate_debug_file (struct objfile *objfile) if (canon_name && strlen (canon_name) > i) i = strlen (canon_name); - debugfile = alloca (strlen (debug_file_directory) + 1 - + i - + strlen (DEBUG_SUBDIRECTORY) - + strlen ("/") - + strlen (basename) - + 1); + debugfile = xmalloc (strlen (debug_file_directory) + 1 + + i + + strlen (DEBUG_SUBDIRECTORY) + + strlen ("/") + + strlen (basename) + + 1); /* First try in the same directory as the original file. */ strcpy (debugfile, dir); strcat (debugfile, basename); if (separate_debug_file_exists (debugfile, crc32, objfile->name)) - { - xfree (basename); - xfree (dir); - xfree (canon_name); - return xstrdup (debugfile); - } + goto cleanup_return_debugfile; /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */ strcpy (debugfile, dir); @@ -1414,12 +1408,7 @@ find_separate_debug_file (struct objfile *objfile) strcat (debugfile, basename); if (separate_debug_file_exists (debugfile, crc32, objfile->name)) - { - xfree (basename); - xfree (dir); - xfree (canon_name); - return xstrdup (debugfile); - } + goto cleanup_return_debugfile; /* Then try in the global debugfile directory. */ strcpy (debugfile, debug_file_directory); @@ -1428,12 +1417,7 @@ find_separate_debug_file (struct objfile *objfile) strcat (debugfile, basename); if (separate_debug_file_exists (debugfile, crc32, objfile->name)) - { - xfree (basename); - xfree (dir); - xfree (canon_name); - return xstrdup (debugfile); - } + goto cleanup_return_debugfile; /* If the file is in the sysroot, try using its base path in the global debugfile directory. */ @@ -1447,20 +1431,17 @@ find_separate_debug_file (struct objfile *objfile) strcat (debugfile, basename); if (separate_debug_file_exists (debugfile, crc32, objfile->name)) - { - xfree (canon_name); - xfree (basename); - xfree (dir); - return xstrdup (debugfile); - } + goto cleanup_return_debugfile; } - if (canon_name) - xfree (canon_name); + xfree (debugfile); + debugfile = NULL; +cleanup_return_debugfile: + xfree (canon_name); xfree (basename); xfree (dir); - return NULL; + return debugfile; }