* [patch 2/3] find_separate_debug_file cleanup
@ 2009-10-21 23:10 Jan Kratochvil
2009-10-22 17:59 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil @ 2009-10-21 23:10 UTC (permalink / raw)
To: gdb-patches
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 <jan.kratochvil@redhat.com>
* 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;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2/3] find_separate_debug_file cleanup
2009-10-21 23:10 [patch 2/3] find_separate_debug_file cleanup Jan Kratochvil
@ 2009-10-22 17:59 ` Tom Tromey
2009-11-02 14:55 ` Jan Kratochvil
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2009-10-22 17:59 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> 2009-10-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Jan> * symfile.c (find_separate_debug_file): Initialize dir, debugfile and
Jan> canon_name to NULL. Change alloca to xmalloc, newly call xfree for it.
Jan> New label cleanup_return_debugfile, jump to it from the failure paths.
Ok.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2/3] find_separate_debug_file cleanup
2009-10-22 17:59 ` Tom Tromey
@ 2009-11-02 14:55 ` Jan Kratochvil
2009-11-02 14:57 ` Jan Kratochvil
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil @ 2009-11-02 14:55 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Thu, 22 Oct 2009 19:59:26 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
> Jan> 2009-10-21 Jan Kratochvil <jan.kratochvil@redhat.com>
> Jan> * symfile.c (find_separate_debug_file): Initialize dir, debugfile and
> Jan> canon_name to NULL. Change alloca to xmalloc, newly call xfree for it.
> Jan> New label cleanup_return_debugfile, jump to it from the failure paths.
>
> Ok.
Checked-in:
http://sourceware.org/ml/gdb-cvs/2009-11/msg00007.html
Thanks,
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2/3] find_separate_debug_file cleanup
2009-11-02 14:55 ` Jan Kratochvil
@ 2009-11-02 14:57 ` Jan Kratochvil
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kratochvil @ 2009-11-02 14:57 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Mon, 02 Nov 2009 15:55:48 +0100, Jan Kratochvil wrote:
> On Thu, 22 Oct 2009 19:59:26 +0200, Tom Tromey wrote:
> > >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> >
> > Jan> 2009-10-21 Jan Kratochvil <jan.kratochvil@redhat.com>
> > Jan> * symfile.c (find_separate_debug_file): Initialize dir, debugfile and
> > Jan> canon_name to NULL. Change alloca to xmalloc, newly call xfree for it.
> > Jan> New label cleanup_return_debugfile, jump to it from the failure paths.
> >
> > Ok.
>
> Checked-in:
> http://sourceware.org/ml/gdb-cvs/2009-11/msg00007.html
Typo, this check-in was:
http://sourceware.org/ml/gdb-cvs/2009-11/msg00008.html
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-02 14:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-21 23:10 [patch 2/3] find_separate_debug_file cleanup Jan Kratochvil
2009-10-22 17:59 ` Tom Tromey
2009-11-02 14:55 ` Jan Kratochvil
2009-11-02 14:57 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox