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


Hi Daniel,

> 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.

Hmm - I should have read all of my emails before replying to Andrew.

Anyway the attached patch fixes the ld testsuite failures by
making add_line_info() take a copy of the filename, using memory
obtained via bfd_alloc().  ie using the same method of obtaining
memory as was used to allocate the info structure itself.  I think
that should prevent further memory leaks.

My previous patch eliminated calls to concat() inside
concat_filename(), which was a good thing, since concat can
potentially call abort.

Of course this still does not fix GDB's problems, but then I am not
sure what problems they are currently having.

Cheers
        Nick

2003-04-01  Nick Clifton  <nickc at redhat dot com>

	* dwarf2.c (add_line_info): Make a copy of the filename when
	storing it into the info structure.

Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.45
diff -c -3 -p -w -r1.45 dwarf2.c
*** bfd/dwarf2.c	1 Apr 2003 10:18:54 -0000	1.45
--- bfd/dwarf2.c	1 Apr 2003 10:27:06 -0000
*************** add_line_info (table, address, filename,
*** 901,910 ****
  
    /* Set member data of 'info'.  */
    info->address = address;
-   info->filename = filename;
    info->line = line;
    info->column = column;
    info->end_sequence = end_sequence;
  }
  
  /* Extract a fully qualified filename from a line info table.
--- 901,919 ----
  
    /* Set member data of 'info'.  */
    info->address = address;
    info->line = line;
    info->column = column;
    info->end_sequence = end_sequence;
+ 
+   amt = strlen (filename);
+   if (amt)
+     {
+       info->filename = bfd_alloc (table->abfd, amt + 1);
+       if (info->filename)
+ 	strcpy (info->filename, filename);
+     }
+   else
+     info->filename = NULL;
  }
  
  /* Extract a fully qualified filename from a line info table.


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