This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems with memory leak fixes


Andrew Cagney <ac131313 at redhat dot com> writes:

|> > As Andrew already pointed out, the use of concat in dwarf2.c is
|> > incorrect. Worse, the fix is incorrect.  The filename is saved in
|> > add_line_info, and
|> > can not be free'd in decode_line_info; fixing this leak will take more
|> > careful attention.  Reverting the patch fixes twelve failures in the LD
|> > testsuite on i686-pc-linux-gnu.
|> > GDB does not use this code so that doesn't explain which fix broke GDB.
|> 
|> It doesn't get BFD off the hook though either.  Reverting the entire BFD
|> part of the change fixes GDB.

Here is a patch, tested on powerpc-linux:

2003-04-01  Andreas Schwab  <schwab at suse dot de>

	* dwarf2.c (add_line_info): Duplicate filename.
	(concat_filename): Use xstrdup instead of concat with one
	argument.  Cast NULL when passed to varargs function.

Index: dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.44
diff -u -p -a -u -p -a -r1.44 dwarf2.c
--- dwarf2.c	1 Apr 2003 00:12:12 -0000	1.44
+++ dwarf2.c	1 Apr 2003 07:31:31 -0000
@@ -901,7 +901,7 @@ add_line_info (table, address, filename,
 
   /* Set member data of 'info'.  */
   info->address = address;
-  info->filename = filename;
+  info->filename = xstrdup (filename);
   info->line = line;
   info->column = column;
   info->end_sequence = end_sequence;
@@ -921,13 +921,13 @@ concat_filename (table, file)
     {
       (*_bfd_error_handler)
 	(_("Dwarf Error: mangled line number section (bad file number)."));
-      return concat ("<unknown>");
+      return xstrdup ("<unknown>");
     }
 
   filename = table->files[file - 1].name;
 
   if (IS_ABSOLUTE_PATH (filename))
-    return concat (filename);
+    return xstrdup (filename);
   else
     {
       char* dirname = (table->files[file - 1].dir
@@ -937,9 +937,9 @@ concat_filename (table, file)
       /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.  The
 	 best we can do is return the filename part.  */
       if (dirname == NULL)
-	return concat (filename);
+	return xstrdup (filename);
       else
-	return concat (dirname, "/", filename, NULL);
+	return concat (dirname, "/", filename, (char *) NULL);
     }
 }
 

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab at suse dot de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]