public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gas/read.c memory leak fix
@ 2002-06-11 11:30 Elias Athanasopoulos
  2002-06-12  7:11 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Elias Athanasopoulos @ 2002-06-11 11:30 UTC (permalink / raw)
  To: binutils

Hi,

I tested it, but I'm not quite sure if it is safe. At least 
register_dependency() uses xstrdup() to duplicate the path, but 
input_scrub_insert_file() eventually calls input_scrub_new_file().

Elias

gas/ChangeLog

2002-06-11  Elias Athanasopoulos  <eathan@otenet.gr>

	* read.c (s_include): Fix memory leak.	

	
--- read.c.orig	Tue Jun 11 20:42:03 2002
+++ read.c	Tue Jun 11 21:29:18 2002
@@ -5121,16 +5121,17 @@
       if (0 != (try = fopen (path, FOPEN_RT)))
 	{
 	  fclose (try);
-	  goto gotit;
+	  register_dependency (path);
+	  input_scrub_insert_file (path);
+	  free (path);
+	  return;
 	}
     }
 
   free (path);
-  path = filename;
-gotit:
-  /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY.  */
-  register_dependency (path);
-  input_scrub_insert_file (path);   
+
+  register_dependency (filename);
+  input_scrub_insert_file (filename);   
 }
 
 void


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gas/read.c memory leak fix
  2002-06-11 11:30 [PATCH] gas/read.c memory leak fix Elias Athanasopoulos
@ 2002-06-12  7:11 ` Nick Clifton
  2002-06-12  7:42   ` Elias Athanasopoulos
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2002-06-12  7:11 UTC (permalink / raw)
  To: Elias Athanasopoulos; +Cc: binutils

Hi Elias,

> I tested it, but I'm not quite sure if it is safe.

It's not.  input_scrub_new_file() records the filename in
physical_input_file, and input_file_open records it in file_name.  To
make the patch safe you would have to add xstrdup()s to both of these
and then arrange for the extra memory to be freed at the right time.

Cheers
        Nick



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gas/read.c memory leak fix
  2002-06-12  7:11 ` Nick Clifton
@ 2002-06-12  7:42   ` Elias Athanasopoulos
  0 siblings, 0 replies; 3+ messages in thread
From: Elias Athanasopoulos @ 2002-06-12  7:42 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Wed, Jun 12, 2002 at 03:08:26PM +0100, Nick Clifton wrote:

> It's not.  input_scrub_new_file() records the filename in
> physical_input_file, and input_file_open records it in file_name.  To
> make the patch safe you would have to add xstrdup()s to both of these
> and then arrange for the extra memory to be freed at the right time.

Yeap. That is exactly what I was afraid of, but I thought it was best
to have the official confirmation. :-)

I'll have a look at physical_input_file and input_file_open and maybe
come again with a new version.

Elias

-- 
http://gnewtellium.sourceforge.net			MP3 is not a crime.	

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-06-12 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-11 11:30 [PATCH] gas/read.c memory leak fix Elias Athanasopoulos
2002-06-12  7:11 ` Nick Clifton
2002-06-12  7:42   ` Elias Athanasopoulos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).