* [RFA] objcopy.c (set_pe_subsystem): plug memory leak
@ 2011-03-08 19:29 Michael Snyder
2011-03-14 12:34 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2011-03-08 19:29 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 5 bytes --]
OK?
[-- Attachment #2: objcopy2.txt --]
[-- Type: text/plain, Size: 1157 bytes --]
2011-03-08 Michael Snyder <msnyder@vmware.com>
* objcopy.c (set_pe_subsystem): Keep temp copy of "copy", so we
can free it before returning.
Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.149
diff -u -p -r1.149 objcopy.c
--- objcopy.c 28 Feb 2011 18:32:51 -0000 1.149
+++ objcopy.c 8 Mar 2011 19:26:36 -0000
@@ -3076,7 +3076,7 @@ strip_main (int argc, char *argv[])
static void
set_pe_subsystem (const char *s)
{
- const char *version, *subsystem;
+ const char *version, *subsystem, *tmp = NULL;
size_t i;
static const struct
{
@@ -3110,6 +3110,7 @@ set_pe_subsystem (const char *s)
int len = version - s;
copy = xstrdup (s);
subsystem = copy;
+ tmp = copy; /* Keep so we can free memory. */
copy[len] = '\0';
version = copy + 1 + len;
pe_major_subsystem_version = strtoul (version, ©, 0);
@@ -3157,6 +3158,7 @@ set_pe_subsystem (const char *s)
pe_section_alignment = PE_DEF_SECTION_ALIGNMENT;
break;
}
+ free (tmp);
}
/* Convert EFI target to PEI target. */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] objcopy.c (set_pe_subsystem): plug memory leak
2011-03-08 19:29 [RFA] objcopy.c (set_pe_subsystem): plug memory leak Michael Snyder
@ 2011-03-14 12:34 ` Richard Sandiford
2011-03-14 20:52 ` Michael Snyder
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2011-03-14 12:34 UTC (permalink / raw)
To: Michael Snyder; +Cc: binutils
Michael Snyder <msnyder@vmware.com> writes:
> 2011-03-08 Michael Snyder <msnyder@vmware.com>
>
> * objcopy.c (set_pe_subsystem): Keep temp copy of "copy", so we
> can free it before returning.
>
> Index: objcopy.c
> ===================================================================
> RCS file: /cvs/src/src/binutils/objcopy.c,v
> retrieving revision 1.149
> diff -u -p -r1.149 objcopy.c
> --- objcopy.c 28 Feb 2011 18:32:51 -0000 1.149
> +++ objcopy.c 8 Mar 2011 19:26:36 -0000
> @@ -3076,7 +3076,7 @@ strip_main (int argc, char *argv[])
> static void
> set_pe_subsystem (const char *s)
> {
> - const char *version, *subsystem;
> + const char *version, *subsystem, *tmp = NULL;
> size_t i;
> static const struct
> {
> @@ -3110,6 +3110,7 @@ set_pe_subsystem (const char *s)
> int len = version - s;
> copy = xstrdup (s);
> subsystem = copy;
> + tmp = copy; /* Keep so we can free memory. */
> copy[len] = '\0';
> version = copy + 1 + len;
> pe_major_subsystem_version = strtoul (version, ©, 0);
> @@ -3157,6 +3158,7 @@ set_pe_subsystem (const char *s)
> pe_section_alignment = PE_DEF_SECTION_ALIGNMENT;
> break;
> }
> + free (tmp);
> }
>
> /* Convert EFI target to PEI target. */
I'd prefer
if (s != subsystem)
free (subsystem);
OK if that works.
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] objcopy.c (set_pe_subsystem): plug memory leak
2011-03-14 12:34 ` Richard Sandiford
@ 2011-03-14 20:52 ` Michael Snyder
0 siblings, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2011-03-14 20:52 UTC (permalink / raw)
To: Michael Snyder, binutils, richard.sandiford
Richard Sandiford wrote:
> Michael Snyder <msnyder@vmware.com> writes:
>> 2011-03-08 Michael Snyder <msnyder@vmware.com>
>>
>> * objcopy.c (set_pe_subsystem): Keep temp copy of "copy", so we
>> can free it before returning.
>>
>> Index: objcopy.c
>> ===================================================================
>> RCS file: /cvs/src/src/binutils/objcopy.c,v
>> retrieving revision 1.149
>> diff -u -p -r1.149 objcopy.c
>> --- objcopy.c 28 Feb 2011 18:32:51 -0000 1.149
>> +++ objcopy.c 8 Mar 2011 19:26:36 -0000
>> @@ -3076,7 +3076,7 @@ strip_main (int argc, char *argv[])
>> static void
>> set_pe_subsystem (const char *s)
>> {
>> - const char *version, *subsystem;
>> + const char *version, *subsystem, *tmp = NULL;
>> size_t i;
>> static const struct
>> {
>> @@ -3110,6 +3110,7 @@ set_pe_subsystem (const char *s)
>> int len = version - s;
>> copy = xstrdup (s);
>> subsystem = copy;
>> + tmp = copy; /* Keep so we can free memory. */
>> copy[len] = '\0';
>> version = copy + 1 + len;
>> pe_major_subsystem_version = strtoul (version, ©, 0);
>> @@ -3157,6 +3158,7 @@ set_pe_subsystem (const char *s)
>> pe_section_alignment = PE_DEF_SECTION_ALIGNMENT;
>> break;
>> }
>> + free (tmp);
>> }
>>
>> /* Convert EFI target to PEI target. */
>
> I'd prefer
>
> if (s != subsystem)
> free (subsystem);
>
> OK if that works.
Done.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-14 20:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 19:29 [RFA] objcopy.c (set_pe_subsystem): plug memory leak Michael Snyder
2011-03-14 12:34 ` Richard Sandiford
2011-03-14 20:52 ` Michael Snyder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).