From patchwork Mon Dec 31 17:17:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30913 Received: (qmail 84923 invoked by alias); 31 Dec 2018 17:17:57 -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 84914 invoked by uid 89); 31 Dec 2018 17:17:57 -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=626, freed X-HELO: mailsec112.isp.belgacom.be Received: from mailsec112.isp.belgacom.be (HELO mailsec112.isp.belgacom.be) (195.238.20.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Dec 2018 17:17:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1546276674; x=1577812674; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5SjwZX1JGcY7wUSjN/YwzwQAxL5iPlwW4Iuozf46dOI=; b=mS8rfGKSU7i06aE76c79cb0RYN7h4BWvpvIxhQvshd14IEiGZpXHw5zC 0EZ5OnunHAg7wcf6bIyRLCXWX2MeqA==; 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; 31 Dec 2018 18:17:52 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak in print_one_catch_syscall. Date: Mon, 31 Dec 2018 18:17:46 +0100 Message-Id: <20181231171746.29652-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes The last text produced was not freed, causing the below leak (e.g. in gdb.base/catch-syscall.exp): ==24970== 56 bytes in 12 blocks are definitely lost in loss record 626 of 3,289 ==24970== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309) ==24970== by 0x66B9C3F: __vasprintf_chk (vasprintf_chk.c:80) ==24970== by 0x405181: vasprintf (stdio2.h:210) ==24970== by 0x405181: xstrvprintf(char const*, __va_list_tag*) (common-utils.c:122) ==24970== by 0x40524B: xstrprintf(char const*, ...) (common-utils.c:113) ==24970== by 0x3B49DB: print_one_catch_syscall(breakpoint*, bp_location**) (break-catch-syscall.c:275) ==24970== by 0x3C698F: print_one_breakpoint_location(breakpoint*, bp_location*, int, bp_location**, int) (breakpoint.c:6076) ==24970== by 0x3C75B1: print_one_breakpoint(breakpoint*, bp_location**, int) (breakpoint.c:6373) ==24970== by 0x3C7D0E: breakpoint_1(char const*, int, int (*)(breakpoint const*)) (breakpoint.c:6571) ==24970== by 0x3C822C: info_breakpoints_command(char const*, int) (breakpoint.c:6625) 2018-12-31 Philippe Waroquiers * break-catch-syscall.c (print_one_catch_syscall): xfree the last text. --- gdb/break-catch-syscall.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 14158d8004..127c5afbeb 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -265,7 +265,7 @@ print_one_catch_syscall (struct breakpoint *b, for (int iter : c->syscalls_to_be_caught) { - char *x = text; + char *previous_text = text; struct syscall s; get_syscall_by_number (gdbarch, iter, &s); @@ -274,14 +274,15 @@ print_one_catch_syscall (struct breakpoint *b, else text = xstrprintf ("%s%d, ", text, iter); - /* We have to xfree the last 'text' (now stored at 'x') - because xstrprintf dynamically allocates new space for it - on every call. */ - xfree (x); + /* We have to xfree previous_text because xstrprintf dynamically + allocates new space for text on every call. */ + xfree (previous_text); } /* Remove the last comma. */ text[strlen (text) - 2] = '\0'; uiout->field_string ("what", text); + /* xfree last text. */ + xfree (text); } else uiout->field_string ("what", "");