This is the mail archive of the gdb@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: Thread bound variable objects


 > > OK, it should be:
 > > 
 > >   +  if (old_cleanups != NULL)
 > >   +    do_cleanups (old_cleanups);
 > 
 > I think that's also wrong. In the event that no cleanups were installed
 > before calling this function, this code will fail to run the
 > cleanups installed by this function. In the event that a cleanup
 > should be really installed conditionally, the right code is:
 > 
 > 	struct cleanups *back_to  = make_cleanup (null_cleanup, NULL);
 > 
 > 	if (...)
 > 		make_cleanup ();
 > 
 > 	do_cleanups (back_to);

OK, I hadn't realised that.  I was looking at other files, e.g., dwarf2read.c
which uses this technique.  That appears to just be with xfree so maybe only
results in a memory leak.

I guess

  struct cleanups *old_cleanups = 0x1;
  ...
  if (old_cleanups != 0x1)
    do_cleanups (old_cleanups);

would work but, as you say, it's probably best to use null_cleanup.


--
Nick                                           http://www.inet.net.nz/~nickrob


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