Bug 26836 - potential memory leak in parse_args
Summary: potential memory leak in parse_args
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.36
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-04 01:34 UTC by GraceLiu
Modified: 2020-12-14 21:33 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description GraceLiu 2020-11-04 01:34:39 UTC
Test case:

#include <stdio.h>
int main()
{
    printf("Hello world!\n");
    return 0;
}

==74578==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 5664 byte(s) in 1 object(s) allocated from:
  #0 0x7fedf6816860 in __interceptor_malloc ../../.././libsanitier/asasn/asan_malloc_linux.cc:62
  #1 0x560879e0b151 in parse_args (/usr/bin/riscv32-unknown-elf-ld+03d151)

binutils version 2.34


Checked on the source code, I did not see any free action on below shortopts, longopts, really_longopts variable.

ld/lexsup.c
  shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
  longopts = (struct option *)
      xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
  really_longopts = (struct option *)
      malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
Comment 1 Sourceware Commits 2020-12-14 13:10:31 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8da4f428d1663541bdd49f5aa2041d06ac6a06de

commit 8da4f428d1663541bdd49f5aa2041d06ac6a06de
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Dec 14 19:34:20 2020 +1030

    PR26836, memory leak in parse_args
    
            PR 26836
            * lexsup.c (parse_args): Free really_longopts, longopts and
            shortopts.
Comment 2 Alan Modra 2020-12-14 21:33:50 UTC
Fixed for 2.36