From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id l+D4ALYla2AoMAAAWB0awg (envelope-from ) for ; Mon, 05 Apr 2021 10:59:02 -0400 Received: by simark.ca (Postfix, from userid 112) id EB13F1E789; Mon, 5 Apr 2021 10:59:01 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2008D1E54D for ; Mon, 5 Apr 2021 10:59:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BE22385803F; Mon, 5 Apr 2021 14:59:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BE22385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617634740; bh=bZM8A8p/bL6KcaU2AZBZocWw5xueUpv03Zh23Lw5jpQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GRbK8sruTDNNOFq5QTE3U+SIeIRyUu0JWd56pc9YXwwevoLm3vAjO8JkMH0adnKXb QFq1Eox3X09uEYjTuQq+9INyrrsG6giI70eSDvczMUKPQrRkc7Plfc5kOhtLeCStD2 FXnJ25oNE+1up0zutEQosdRM8PmeYbAMK44HVW28= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 40543385803F for ; Mon, 5 Apr 2021 14:58:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 40543385803F X-ASG-Debug-ID: 1617634737-0c856e67e2bd8a10001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id vwBZ4DJj0IpzEKtk (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 05 Apr 2021 10:58:57 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 2BF00441D64; Mon, 5 Apr 2021 10:58:57 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH] sim/m32c: fix memory leaks in opc2c Date: Mon, 5 Apr 2021 10:58:56 -0400 X-ASG-Orig-Subj: [PATCH] sim/m32c: fix memory leaks in opc2c Message-Id: <20210405145856.3925296-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1617634737 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 3001 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.89032 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" When building with AddressSanitizer, sim/m32c fails with: ./opc2c -l r8c.out /home/simark/src/binutils-gdb/sim/m32c/r8c.opc > r8c.c sim_log: r8c.out ================================================================= ==3919390==ERROR: LeakSanitizer: detected memory leaks Direct leak of 485 byte(s) in 131 object(s) allocated from: #0 0x7ffff761fa69 in __interceptor_strdup /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:452 #1 0x555555557abe in dump_lines /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:243 #2 0x555555558bc9 in emit_indirect /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:382 #3 0x555555558c66 in emit_indirect /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:387 #4 0x55555555c463 in main /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:718 #5 0x7ffff741fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) Direct leak of 360 byte(s) in 100 object(s) allocated from: #0 0x7ffff761fa69 in __interceptor_strdup /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:452 #1 0x555555557abe in dump_lines /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:243 #2 0x555555558bc9 in emit_indirect /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:382 #3 0x55555555c463 in main /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:718 #4 0x7ffff741fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) Direct leak of 4 byte(s) in 1 object(s) allocated from: #0 0x7ffff7677459 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x55555555b3df in main /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:658 #2 0x7ffff741fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) Fix the leak in dump_lines by free-ing the elements of varnames. Fix the leak in main by removing the vlist variable, which seems unused. sim/m32c/ChangeLog: * opc2c.c (dump_lines): Free elements of varnames. (main): Remove vlist variable. Change-Id: I5a92fd229da623bd32841b083c54c5c868455e91 --- sim/m32c/opc2c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sim/m32c/opc2c.c b/sim/m32c/opc2c.c index 082d4e9b8a42..7d1604f4fb3a 100644 --- a/sim/m32c/opc2c.c +++ b/sim/m32c/opc2c.c @@ -286,6 +286,9 @@ dump_lines (opcode * op, int level, Indirect * ind) printf ("%*s%s", level, "", op->lines[i]); if (op->comment) printf ("%*s}\n", level, ""); + + for (i = 0; i < vn; i++) + free (varnames[i]); } void @@ -507,7 +510,6 @@ main (int argc, char **argv) FILE *in; int lineno = 0; int i; - VaryRef *vlist; if (argc > 2 && strcmp (argv[1], "-l") == 0) { @@ -655,8 +657,6 @@ main (int argc, char **argv) qsort (opcodes, n_opcodes, sizeof (opcodes[0]), op_cmp); - vlist = (VaryRef *) malloc (n_varies * sizeof (VaryRef)); - for (i = 0; i < n_opcodes; i++) { int j, b, v; -- 2.30.1