This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] libiberty/argv.c: Use freeargv() instead of free() to avoid memory leak.
- From: DJ Delorie <dj at redhat dot com>
- To: Chen Gang S <gang dot chen at sunrus dot com dot cn>
- Cc: ian at airs dot com, binutils at sourceware dot org, gcc-patches at gcc dot gnu dot org, law at redhat dot com
- Date: Wed, 28 Jan 2015 16:19:04 -0500
- Subject: Re: [PATCH] libiberty/argv.c: Use freeargv() instead of free() to avoid memory leak.
- Authentication-results: sourceware.org; auth=none
- References: <54C8C94E dot 9030305 at sunrus dot com dot cn>
> memcpy (*argvp + i, file_argv, file_argc * sizeof (char *));
This code copies all the pointers in file_argv[] into argv[], so if
you freeargv them via file_argv, argv[] will point to free'd memory.
Hence the comment:
> /* Free up memory allocated to process the response file. We do
> not use freeargv because the individual options in FILE_ARGV
> are now in the main ARGV. */