public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* xfree/make_cleanup memory leak pattern?
@ 2012-01-11  0:25 Khoo Yit Phang
  2012-01-11  0:31 ` Jan Kratochvil
  0 siblings, 1 reply; 4+ messages in thread
From: Khoo Yit Phang @ 2012-01-11  0:25 UTC (permalink / raw)
  To: gdb; +Cc: Khoo Yit Phang

Hi,

I noticed the following code pattern in various places in GDB:
	script = compute_python_string (cmd->body_list[0]);
	...
	xfree (script);

and also others like:
	full_path = tilde_expand (filename);
	...
	cleanup = make_cleanup (xfree, full_path); 

If I understand correctly, wouldn't these patterns lead to a memory leak if the user manages to trigger a SIGINT (with immediate_quit in effect) at the "..." in between the memory allocation and xfree/make_cleanup? It's a tiny window in most cases, but something like compute_python_string could take some time.

Yit
January 10, 2012

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: xfree/make_cleanup memory leak pattern?
  2012-01-11  0:25 xfree/make_cleanup memory leak pattern? Khoo Yit Phang
@ 2012-01-11  0:31 ` Jan Kratochvil
  2012-01-11  0:32   ` Jan Kratochvil
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil @ 2012-01-11  0:31 UTC (permalink / raw)
  To: Khoo Yit Phang; +Cc: gdb

On Wed, 11 Jan 2012 01:25:06 +0100, Khoo Yit Phang wrote:
> I noticed the following code pattern in various places in GDB:
> 	script = compute_python_string (cmd->body_list[0]);
> 	...
> 	xfree (script);
> 
> and also others like:
> 	full_path = tilde_expand (filename);
> 	...
> 	cleanup = make_cleanup (xfree, full_path); 

immediate_quit will cause:
	fatal ("Quit");

which calls throw_exception in the end so all the intermediate cleanup
functions get called.  You can trace/debug it yourself.

I do not see a leak there.  Could you provide some debugging output proving
the memory is being leaked?


Thanks,
Jan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: xfree/make_cleanup memory leak pattern?
  2012-01-11  0:31 ` Jan Kratochvil
@ 2012-01-11  0:32   ` Jan Kratochvil
  2012-01-11 14:31     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil @ 2012-01-11  0:32 UTC (permalink / raw)
  To: Khoo Yit Phang; +Cc: gdb

On Wed, 11 Jan 2012 01:30:35 +0100, Jan Kratochvil wrote:
> I do not see a leak there.  Could you provide some debugging output proving
> the memory is being leaked?

Sorry, this was bogus reply.

Yes, I agree.  immediate_quit is not well handled.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: xfree/make_cleanup memory leak pattern?
  2012-01-11  0:32   ` Jan Kratochvil
@ 2012-01-11 14:31     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2012-01-11 14:31 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Khoo Yit Phang, gdb

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> Yes, I agree.  immediate_quit is not well handled.

I think it is only used in selected spots.

I wonder if we could enhance the exception checker to look for problems
in this area.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-11 14:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-11  0:25 xfree/make_cleanup memory leak pattern? Khoo Yit Phang
2012-01-11  0:31 ` Jan Kratochvil
2012-01-11  0:32   ` Jan Kratochvil
2012-01-11 14:31     ` Tom Tromey

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).