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]

A patch for memory leak in gas


There may be a memory leak in listing_message (). Here is a patch.

-- 
H.J. Lu (hjl@valinux.com)
---
2000-12-29  H.J. Lu  <hjl@gnu.org>

	* listing.c (listing_message): Allocate string only if it is
	used.

Index: listing.c
===================================================================
RCS file: /work/cvs/gnu/binutils/gas/listing.c,v
retrieving revision 1.6
diff -u -p -r1.6 listing.c
--- listing.c	2000/11/08 00:33:58	1.6
+++ listing.c	2000/12/29 21:56:49
@@ -226,12 +226,12 @@ listing_message (name, message)
      const char *name;
      const char *message;
 {
-  unsigned int l = strlen (name) + strlen (message) + 1;
-  char *n = (char *) xmalloc (l);
-  strcpy (n, name);
-  strcat (n, message);
   if (listing_tail != (list_info_type *) NULL)
     {
+      unsigned int l = strlen (name) + strlen (message) + 1;
+      char *n = (char *) xmalloc (l);
+      strcpy (n, name);
+      strcat (n, message);
       listing_tail->message = n;
     }
 }

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