1 http://sourceware.org/ml/gdb-patches/2009-10/msg00509.html
2 Subject: [patch 2/3] find_separate_debug_file cleanup
7 * difficult to maintain as a new variable required xfree on many places
8 * was causing memory corruptions due to silently misapplied 3rd party patches
9 as the close code fragments unfortunately match patch context
17 2009-10-21 Jan Kratochvil <jan.kratochvil@redhat.com>
19 * symfile.c (find_separate_debug_file): Initialize dir, debugfile and
20 canon_name to NULL. Change alloca to xmalloc, newly call xfree for it.
21 New label cleanup_return_debugfile, jump to it from the failure paths.
25 @@ -1333,11 +1333,10 @@ static char *
26 find_separate_debug_file (struct objfile *objfile)
34 + char *basename, *name_copy;
36 + char *debugfile = NULL;
37 + char *canon_name = NULL;
38 bfd_size_type debuglink_size;
41 @@ -1366,7 +1365,7 @@ find_separate_debug_file (struct objfile *objfile)
43 /* There's no separate debug info, hence there's no way we could
44 load it => no warning. */
46 + goto cleanup_return_debugfile;
48 dir = xstrdup (objfile->name);
50 @@ -1388,24 +1387,19 @@ find_separate_debug_file (struct objfile *objfile)
51 if (canon_name && strlen (canon_name) > i)
52 i = strlen (canon_name);
54 - debugfile = alloca (strlen (debug_file_directory) + 1
56 - + strlen (DEBUG_SUBDIRECTORY)
60 + debugfile = xmalloc (strlen (debug_file_directory) + 1
62 + + strlen (DEBUG_SUBDIRECTORY)
67 /* First try in the same directory as the original file. */
68 strcpy (debugfile, dir);
69 strcat (debugfile, basename);
71 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
76 - return xstrdup (debugfile);
78 + goto cleanup_return_debugfile;
80 /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
81 strcpy (debugfile, dir);
82 @@ -1414,12 +1408,7 @@ find_separate_debug_file (struct objfile *objfile)
83 strcat (debugfile, basename);
85 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
90 - return xstrdup (debugfile);
92 + goto cleanup_return_debugfile;
94 /* Then try in the global debugfile directory. */
95 strcpy (debugfile, debug_file_directory);
96 @@ -1428,12 +1417,7 @@ find_separate_debug_file (struct objfile *objfile)
97 strcat (debugfile, basename);
99 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
103 - xfree (canon_name);
104 - return xstrdup (debugfile);
106 + goto cleanup_return_debugfile;
108 /* If the file is in the sysroot, try using its base path in the
109 global debugfile directory. */
110 @@ -1447,20 +1431,17 @@ find_separate_debug_file (struct objfile *objfile)
111 strcat (debugfile, basename);
113 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
115 - xfree (canon_name);
118 - return xstrdup (debugfile);
120 + goto cleanup_return_debugfile;
124 - xfree (canon_name);
128 +cleanup_return_debugfile:
129 + xfree (canon_name);