bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/28448] New: Memory leak in add_symbols(plugin.c)


From: yuxian.chen at intel dot com
Subject: [Bug ld/28448] New: Memory leak in add_symbols(plugin.c)
Date: Wed, 13 Oct 2021 08:11:45 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=28448

            Bug ID: 28448
           Summary: Memory leak in add_symbols(plugin.c)
           Product: binutils
           Version: 2.32
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: yuxian.chen at intel dot com
  Target Milestone: ---

BFD linker allocates memory to store symbols but the memory is not freed after
add_symbols function is done.
Memory leak issue can be seen by running Valgrind.

How to reproduce:
bash-4.4$ cat simple.c
#include <stdio.h>
int foo();int main() {
  printf("%d", foo());
  return 0;
}
bash-4.4$ cat foo.c
int foo() {
  return 1;
}
bash-4.4$ valgrind --tool=memcheck --trace-children=yes --leak-check=full
--leak-resolution=med --show-leak-kinds=definite
--errors-for-leak-kinds=definite --error-limit=no gcc -Wl,-z,muldefs
-mfpmath=sse -O3 -ffast-math -funroll-loops -flto simple.c foo.c
Output:
==3559396== 24 bytes in 2 blocks are definitely lost in loss record 19 of 171
==3559396==    at 0x4C30F93: malloc (vg_replace_malloc.c:307)
==3559396==    by 0x4DDD27: xmalloc (xmalloc.c:147)
==3559396==    by 0x41FBC6: add_symbols (plugin.c:493)
==3559396==    by 0x127BDD8D: ???
==3559396==    by 0x420593: plugin_call_claim_file (plugin.c:1052)
==3559396==    by 0x420593: plugin_object_p (plugin.c:1130)
==3559396==    by 0x420D06: plugin_maybe_claim (plugin.c:1184)
==3559396==    by 0x41DE7B: ldfile_try_open_bfd (ldfile.c:318)
==3559396==    by 0x41E41B: ldfile_open_file (ldfile.c:401)
==3559396==    by 0x4111FA: load_symbols (ldlang.c:2949)
==3559396==    by 0x411ED6: open_input_bfds (ldlang.c:3529)
==3559396==    by 0x414348: lang_process (ldlang.c:7383)
==3559396==    by 0x402E4F: main (ldmain.c:440)


Source code:

static enum ld_plugin_status
add_symbols (void *handle, int nsyms, const struct ld_plugin_symbol *syms)
{
  asymbol **symptrs;
  plugin_input_file_t *input = handle;
  bfd *abfd = input->abfd;
  int n;  ASSERT (called_plugin);
  symptrs = xmalloc (nsyms * sizeof *symptrs);
  for (n = 0; n < nsyms; n++)
    {
      enum ld_plugin_status rv;
      asymbol *bfdsym;      bfdsym = bfd_make_empty_symbol (abfd);
      symptrs[n] = bfdsym;
      rv = asymbol_from_plugin_symbol (abfd, bfdsym, syms + n);
      if (rv != LDPS_OK)
        return rv;
    }
  bfd_set_symtab (abfd, symptrs, nsyms);
  return LDPS_OK;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

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