Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Fix leak of struct call_thread_fsm in call_function_by_hand_dummy.
@ 2019-01-02 17:14 Philippe Waroquiers
  2019-01-02 18:54 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Waroquiers @ 2019-01-02 17:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

When the call does not complete, the call_thread_fsm allocated
by new_call_thread_fsm is not cleaned up and deleted, which causes
the following leak e.g. in gdb.base/callfuncs.exp:

==29263== 560 bytes in 7 blocks are definitely lost in loss record 2,833 of 3,341
==29263==    at 0x4C2E0BC: calloc (vg_replace_malloc.c:762)
==29263==    by 0x405110: xcalloc (common-utils.c:84)
==29263==    by 0x4E67EB: xcnew<call_thread_fsm> (poison.h:122)
==29263==    by 0x4E67EB: new_call_thread_fsm (infcall.c:516)
==29263==    by 0x4E67EB: call_function_by_hand_dummy(value*, type*, gdb::array_view<value*>, void (*)(void*, int), void*) (infcall.c:1154)
==29263==    by 0x4E784E: call_function_by_hand(value*, type*, gdb::array_view<value*>) (infcall.c:693)
==29263==    by 0x496111: eval_call(expression*, noside, int, value**, char const*, type*) [clone .isra.5] (eval.c:835)

Fix the leak by similarly doing cleanup/destroy when restoring
previous state machine.

Tested on debian/amd64, natively and under valgrind.

2019-01-02  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* infcall.c (call_function_by_hand_dummy): cleanup/destroy sm
	 in case of call that did not complete.
---
 gdb/infcall.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/infcall.c b/gdb/infcall.c
index 2a01d70013..14b0cbc716 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -1189,8 +1189,10 @@ call_function_by_hand_dummy (struct value *function,
 	    return retval;
 	  }
 
-	/* Didn't complete.  Restore previous state machine, and
-	   handle the error.  */
+	/* Didn't complete.  Clean up / destroy the call FSM, and restore the
+	   previous state machine, and handle the error.  */
+	thread_fsm_clean_up (call_thread->thread_fsm, call_thread.get ());
+	thread_fsm_delete (call_thread->thread_fsm);
 	call_thread->thread_fsm = saved_sm;
       }
   }
-- 
2.19.2


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

* Re: [RFA] Fix leak of struct call_thread_fsm in call_function_by_hand_dummy.
  2019-01-02 17:14 [RFA] Fix leak of struct call_thread_fsm in call_function_by_hand_dummy Philippe Waroquiers
@ 2019-01-02 18:54 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2019-01-02 18:54 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: gdb-patches

>>>>> "Philippe" == Philippe Waroquiers <philippe.waroquiers@skynet.be> writes:

Philippe> Fix the leak by similarly doing cleanup/destroy when restoring
Philippe> previous state machine.

Philippe> Tested on debian/amd64, natively and under valgrind.

Philippe> 2019-01-02  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

Philippe> 	* infcall.c (call_function_by_hand_dummy): cleanup/destroy sm
Philippe> 	 in case of call that did not complete.

This is ok.  Thanks.

Tom


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

end of thread, other threads:[~2019-01-02 18:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-02 17:14 [RFA] Fix leak of struct call_thread_fsm in call_function_by_hand_dummy Philippe Waroquiers
2019-01-02 18:54 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox