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]

[tv] Patch: fix _bfd_window_internal::refcount for mmap


The following change is a trivial one-liner from Matthias Scheler out of the
NetBSD source tree, which fixes a nasty memory chewing bug.  I do not
currently know if Matthias has copyright assignments on file, but the
one-line change should be acceptable.

In the mmap case, _bfd_window_internal::refcount is not being initialized,
and thus the reference count of the window remains at 0 while in use.  At
bfd_free_window() time, refcount is decremented--to -1, which does not equal
zero (resulting in the window remaining allocated).  This can result in
chewing a lot of memory when doing a recursive operation (say, "nm") on a
library archive.

This change initializes refcount to 1 when using mmap(), so that the
segments will actually be freed at bfd_free_window() time.

=====

bfd/ChangeLog entry:

2001-01-31  Matthias Scheler  <tron@netbsd.org>

	* libbfd.c (bfd_get_file_window): Initialize i->refcount to 1 if
	using mmap.

=====

Diff against binutils HEAD (may also be applied to the 2.11 and 2.10
branches, if desired):

Index: bfd/libbfd.c
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.c,v
retrieving revision 1.14
diff -u -r1.14 libbfd.c
--- bfd/libbfd.c	2001/01/03 19:26:07	1.14
+++ bfd/libbfd.c	2001/01/31 17:41:06
@@ -462,6 +462,7 @@
       i->size = real_size;
       windowp->data = (PTR) ((bfd_byte *) i->data + offset2);
       windowp->size = size;
+      i->refcount = 1;
       i->mapped = 1;
       return true;
     }

-- 
-- Todd Vierling <tv@wasabisystems.com>  *  Wasabi NetBSD:  Run with it.
-- NetBSD 1.5 now available on CD-ROM  --  http://www.wasabisystems.com/


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