bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"size" leaks memory, and then BFD segfaults


From: Bob Byrnes
Subject: "size" leaks memory, and then BFD segfaults
Date: Fri, 3 May 2002 19:42:26 -0400

I am using the latest binutils-2.12:

----------------------------------------
shell> size --version
GNU size 2.12
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
----------------------------------------

The "size" program leaks memory when reporting on archives.
This is easy to reproduce: just pass a few hundred fairly
large archives on the command line, and watch the memory use.

The reason for this is that "size" fails to close the archive
elements (unlike the other programs, like "nm" or "objdump").
The patch below seems to fix the problem, using the same
technique employed by the other programs.

When "size" was running out of memory, it tended to segfault
within _bfd_new_bfd_contained_in().  The reason is that this
function fails to check the pointer returned by _bfd_new_bfd()
(unlike the other allocation functions).  The patch below adds
the same check used elsewhere, so the failure will not be
catastrophic.

Bob Byrnes                        e-mail: address@hidden
Curl Corporation                  phone:  617-761-1200
400 Technology Square, 8th Floor  fax:    617-761-1201
Cambridge, MA  02139

Index: binutils/size.c
===================================================================
RCS file: /projects/systems/cvs-root/gnu/binutils/binutils/size.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 size.c
--- binutils/size.c     2002/05/03 19:24:06     1.1.1.4
+++ binutils/size.c     2002/05/03 23:19:06
@@ -316,6 +316,7 @@
      bfd *file;
 {
   bfd *arfile = (bfd *) NULL;
+  bfd *last_arfile = (bfd *) NULL;
 
   for (;;)
     {
@@ -333,8 +334,14 @@
        }
 
       display_bfd (arfile);
-      /* Don't close the archive elements; we need them for next_archive.  */
+    
+      if (last_arfile != NULL)
+       bfd_close (last_arfile);
+      last_arfile = arfile;
     }
+
+  if (last_arfile != NULL)
+    bfd_close (last_arfile);
 }
 
 static void

Index: bfd/opncls.c
===================================================================
RCS file: /projects/systems/cvs-root/gnu/binutils/bfd/opncls.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 opncls.c
--- bfd/opncls.c        2002/05/03 19:24:26     1.1.1.4
+++ bfd/opncls.c        2002/05/03 22:25:14
@@ -96,6 +96,8 @@
   bfd *nbfd;
 
   nbfd = _bfd_new_bfd ();
+  if (nbfd == NULL)
+    return NULL;
   nbfd->xvec = obfd->xvec;
   nbfd->my_archive = obfd;
   nbfd->direction = read_direction;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]