From patchwork Wed Jan 2 17:14:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30938 Received: (qmail 102758 invoked by alias); 2 Jan 2019 17:14:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 102209 invoked by uid 89); 2 Jan 2019 17:14:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mailsec114.isp.belgacom.be Received: from mailsec114.isp.belgacom.be (HELO mailsec114.isp.belgacom.be) (195.238.20.110) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Jan 2019 17:14:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1546449283; x=1577985283; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=oqgDbzelL6hyK0V+n2qMWNdaOPcoT6Yb2qsIdWpfuHo=; b=gumuM2iHxqbV6y+h4fiOx+8JQYAyiH+o3gu3NjA0QxxWGH2m9MfLrEVy +NZr7V1dCPLnzZPEl5yuhGDtUXfohg==; Received: from 184.205-67-87.adsl-dyn.isp.belgacom.be (HELO md.home) ([87.67.205.184]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 02 Jan 2019 18:14:40 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak of struct call_thread_fsm in call_function_by_hand_dummy. Date: Wed, 2 Jan 2019 18:14:35 +0100 Message-Id: <20190102171435.20402-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 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 (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, void (*)(void*, int), void*) (infcall.c:1154) ==29263== by 0x4E784E: call_function_by_hand(value*, type*, gdb::array_view) (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 * 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; } }