Re: [RFC-v4] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)

Tom Tromey
2012-11-26T16:54:16Z

>>>>> "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, &section_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