This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC-v4] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)
- From: Tom Tromey <tromey at redhat dot com>
- To: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- Cc: "'Joel Brobecker'" <brobecker at adacore dot com>, "'Pedro Alves'" <palves at redhat dot com>, "'Eli Zaretskii'" <eliz at gnu dot org>, <gdb-patches at sourceware dot org>
- Date: Mon, 26 Nov 2012 09:53:48 -0700
- Subject: Re: [RFC-v4] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)
- References: <834nm07z0s.fsf@gnu.org> <5077FEB9.4030304@redhat.com> <83y5jb7rfe.fsf@gnu.org> <006001cdaada$00c81f00$02585d00$@muller@ics-cnrs.unistra.fr> <20121024194517.GK3555@adacore.com> <011901cdb2ab$48076b90$d81642b0$@muller@ics-cnrs.unistra.fr> <20121105171121.GA2972@adacore.com> <50991f5f.8382440a.1100.ffff82abSMTPIN_ADDED@mx.google.com> <509ABA17.30507@redhat.com> <000301cdbd96$f5cd9f10$e168dd30$@muller@ics-cnrs.unistra.fr> <20121122173019.GF9964@adacore.com> <15690.5992342674$1353883881@news.gmane.org>
>>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr> writes:
Joel> Are we missing a cleanup/xfree?
Pierre> I added some, please check that part, as I have
Pierre> no experience at all with using make_cleanup
Pierre> related functions...
Pierre> In particular, I didn't really get if it is OK to call
Pierre> do_cleanups with a possibly NULL argument...
The simplest way to approach cleanups, which I recommend in nearly all
cases, is to treat them as block-scoped and to always pass the result of
a make_cleanup call to do_cleanups. Try to avoid tricks with conditions
and possibly-NULL cleanup pointers, this usually leads to trouble.
Pierre> + struct cleanup *section_cleanup = 0;
I think there's no need to initialize this, since you re-set it later.
Pierre> + section_data = xzalloc (PE_SECTION_TABLE_SIZE
Pierre> + * sizeof (struct read_pe_section_data));
Pierre> +
Pierre> + section_cleanup = make_cleanup (xfree, section_data);
Ok so far, but...
Pierre> + section_data = xrealloc (section_data, otherix
Pierre> + * sizeof (struct read_pe_section_data));
... this can free the original pointer.
What you want is:
section_cleanup = make_cleanup (free_current_contents, §ion_data);
This will free the current value of the pointer, instead of capturing
the value when the cleanup is made.
Pierre> /* Discard expdata. */
Pierre> do_cleanups (back_to);
Pierre> + /* Discard section_data. */
Pierre> + do_cleanups (section_cleanup);
Cleanups are a stack, so you can just invoke do_cleanups on the
outermost one. Just delete the local variable 'back_to'.
Tom