Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Oct 2008 22:50:19 -0700 (PDT)
From:      "Dorr H. Clark" <dclark@engr.scu.edu>
To:        freebsd-ports-bugs@freebsd.org
Cc:        freebsd-bugs@freebsd.org
Subject:   patch for memory leak in libbfd 
Message-ID:  <Pine.GSO.4.21.0810072244350.3445-100000@nova41.dc.engr.scu.edu>

next in thread | raw e-mail | index | archive | help

While working with the version of libbfd which ships with FreeBSD 6.3, 
we found a memory leak.  The memory leak is fixed in a more recent
version of libbfd, but some people may not want to upgrade.

For this reason, we have back-ported a patch to libbfd 
to address the memory leak in the shipping version.

Patch follows.

Sunitha Nagendra
Engineer

Dorr H. Clark
Advisor

Graduate School of Engineering
Santa Clara University
Santa Clara, CA.

http://www.cse.scu.edu/~dclark/coen_284_FreeBSD/libbfd_patch.txt

contrib/binutils/bfd/dwarf2.c

491,498c491,516
< 	  if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
< 	    {
< 	      amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
< 	      amt *= sizeof (struct attr_abbrev);
< 	      cur_abbrev->attrs = bfd_realloc (cur_abbrev->attrs, amt);
< 	      if (! cur_abbrev->attrs)
< 		return 0;
< 	    }
---
> 
>           if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
>             {
>               struct attr_abbrev *tmp;
> 
>               amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
>               amt *= sizeof (struct attr_abbrev);
>               tmp = bfd_realloc (cur_abbrev->attrs, amt);
>               if (tmp == NULL)
>                 {
>                   size_t i;
> 
>                   for (i = 0; i < ABBREV_HASH_SIZE; i++)
>                     {
>                       struct abbrev_info *abbrev = abbrevs[i];
> 
>                       while (abbrev)
>                         {
>                           free (abbrev->attrs);
>                           abbrev = abbrev->next;
>                         }
>                     }
>                   return NULL;
>                 }
>               cur_abbrev->attrs = tmp;
>             }
1876a1895,1936
> 
> void
> _bfd_dwarf2_cleanup_debug_info (bfd *abfd)
> {
>   struct comp_unit *each;
>   struct dwarf2_debug *stash;
> 
>   if (abfd == NULL || elf_tdata (abfd) == NULL)
>     return;
> 
>   stash = elf_tdata (abfd)->dwarf2_find_line_info;
> 
>   if (stash == NULL)
>     return;
> 
>   for (each = stash->all_comp_units; each; each = each->next_unit)
>     {
>       struct abbrev_info **abbrevs = each->abbrevs;
>       size_t i;
> 
>       for (i = 0; i < ABBREV_HASH_SIZE; i++)
>         {
>           struct abbrev_info *abbrev = abbrevs[i];
> 
>           while (abbrev)
>             {
>               free (abbrev->attrs);
>               abbrev = abbrev->next;
>             }
>         }
> 
>       if (each->line_table)
>         {
>           free (each->line_table->dirs);
>           free (each->line_table->files);
>         }
>     }
> 
>   free (stash->dwarf_abbrev_buffer);
>   free (stash->dwarf_line_buffer);
> }
> 

contrib/binutils/bfd/elf-bfd.h

1639a1640,1643
> 
> extern void _bfd_dwarf2_cleanup_debug_info
>   (bfd *);
> 

contrib/binutils/bfd/elf.c

6291a6292
> 	_bfd_dwarf2_cleanup_debug_info (abfd);




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.21.0810072244350.3445-100000>