]>
Commit | Line | Data |
---|---|---|
ab050a48 BZ |
1 | http://sourceware.org/ml/gdb-patches/2009-10/msg00509.html |
2 | Subject: [patch 2/3] find_separate_debug_file cleanup | |
3 | ||
4 | Hi, | |
5 | ||
6 | current code was: | |
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 | |
10 | ||
11 | ||
12 | Thanks, | |
13 | Jan | |
14 | ||
15 | ||
16 | gdb/ | |
17 | 2009-10-21 Jan Kratochvil <jan.kratochvil@redhat.com> | |
18 | ||
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. | |
22 | ||
23 | --- a/gdb/symfile.c | |
24 | +++ b/gdb/symfile.c | |
25 | @@ -1333,11 +1333,10 @@ static char * | |
26 | find_separate_debug_file (struct objfile *objfile) | |
27 | { | |
28 | asection *sect; | |
29 | - char *basename; | |
30 | - char *dir; | |
31 | - char *debugfile; | |
32 | - char *name_copy; | |
33 | - char *canon_name; | |
34 | + char *basename, *name_copy; | |
35 | + char *dir = NULL; | |
36 | + char *debugfile = NULL; | |
37 | + char *canon_name = NULL; | |
38 | bfd_size_type debuglink_size; | |
39 | unsigned long crc32; | |
40 | int i; | |
41 | @@ -1366,7 +1365,7 @@ find_separate_debug_file (struct objfile *objfile) | |
42 | if (basename == NULL) | |
43 | /* There's no separate debug info, hence there's no way we could | |
44 | load it => no warning. */ | |
45 | - return NULL; | |
46 | + goto cleanup_return_debugfile; | |
47 | ||
48 | dir = xstrdup (objfile->name); | |
49 | ||
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); | |
53 | ||
54 | - debugfile = alloca (strlen (debug_file_directory) + 1 | |
55 | - + i | |
56 | - + strlen (DEBUG_SUBDIRECTORY) | |
57 | - + strlen ("/") | |
58 | - + strlen (basename) | |
59 | - + 1); | |
60 | + debugfile = xmalloc (strlen (debug_file_directory) + 1 | |
61 | + + i | |
62 | + + strlen (DEBUG_SUBDIRECTORY) | |
63 | + + strlen ("/") | |
64 | + + strlen (basename) | |
65 | + + 1); | |
66 | ||
67 | /* First try in the same directory as the original file. */ | |
68 | strcpy (debugfile, dir); | |
69 | strcat (debugfile, basename); | |
70 | ||
71 | if (separate_debug_file_exists (debugfile, crc32, objfile->name)) | |
72 | - { | |
73 | - xfree (basename); | |
74 | - xfree (dir); | |
75 | - xfree (canon_name); | |
76 | - return xstrdup (debugfile); | |
77 | - } | |
78 | + goto cleanup_return_debugfile; | |
79 | ||
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); | |
84 | ||
85 | if (separate_debug_file_exists (debugfile, crc32, objfile->name)) | |
86 | - { | |
87 | - xfree (basename); | |
88 | - xfree (dir); | |
89 | - xfree (canon_name); | |
90 | - return xstrdup (debugfile); | |
91 | - } | |
92 | + goto cleanup_return_debugfile; | |
93 | ||
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); | |
98 | ||
99 | if (separate_debug_file_exists (debugfile, crc32, objfile->name)) | |
100 | - { | |
101 | - xfree (basename); | |
102 | - xfree (dir); | |
103 | - xfree (canon_name); | |
104 | - return xstrdup (debugfile); | |
105 | - } | |
106 | + goto cleanup_return_debugfile; | |
107 | ||
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); | |
112 | ||
113 | if (separate_debug_file_exists (debugfile, crc32, objfile->name)) | |
114 | - { | |
115 | - xfree (canon_name); | |
116 | - xfree (basename); | |
117 | - xfree (dir); | |
118 | - return xstrdup (debugfile); | |
119 | - } | |
120 | + goto cleanup_return_debugfile; | |
121 | } | |
122 | ||
123 | - if (canon_name) | |
124 | - xfree (canon_name); | |
125 | + xfree (debugfile); | |
126 | + debugfile = NULL; | |
127 | ||
128 | +cleanup_return_debugfile: | |
129 | + xfree (canon_name); | |
130 | xfree (basename); | |
131 | xfree (dir); | |
132 | - return NULL; | |
133 | + return debugfile; | |
134 | } | |
135 | ||
136 | ||
137 |