This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [OB] Add cleanup, source.c


> On Thu, Jun 28, 2007 at 03:59:23PM -0700, Michael Snyder wrote:
>>
>>
>> > There's no call to do_cleanups in this function, so it's quite hard to
>> > see if this cleanup will be run or discarded if error is not called.
>>
>> When are they ever discarded?
>>
>> My last understanding of the mechanism was that the cleanups
>> always get called, eventually.  Presumably when we return to
>> the command / event loop.
>
> No, that's not right.  Cleanups are often discarded after a successful
> operation, in order to not free something that would have been cleaned
> up on error.

Well, I'm pretty sure you're mistaken.

Or put it another way -- one of us is mistaken, and naturally,
I think it's you.   ;-)

1) From logic: I know that frequently when we allocate something,
we call a make_cleanup function to register it to be freed -- and
then we never actually free it.  We depend on it being freed at
cleanup time.  Which is exactly what we're doing here.

2) Empirically: I run gdb with this change, and set a breakpoint
at do_freeargv.  It gets called, from command_handler (event-top.c).
So the change accomplishes what it is meant to do.

3) By example: in the same module (source.c), three other functions
call buildargv and make_cleanup_freeargv -- and none of them calls
do_cleanups.

So you're holding me to a higher standard than the preexisting code.
;-)





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]