From patchwork Thu Aug 12 13:09:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Simpson X-Patchwork-Id: 1516281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcdkim header.b=avizhTII; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GlnBD3RqHz9sPf for ; Thu, 12 Aug 2021 23:11:00 +1000 (AEST) Received: from localhost ([::1]:50514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEAU4-0003R0-Vd for incoming@patchwork.ozlabs.org; Thu, 12 Aug 2021 09:10:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEASg-0001xX-Gx for qemu-devel@nongnu.org; Thu, 12 Aug 2021 09:09:30 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:18398) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1mEASe-0007w0-Cq for qemu-devel@nongnu.org; Thu, 12 Aug 2021 09:09:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1628773768; x=1660309768; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5N1bCNbN1LRAFl+23WVyBxds2Z76PV4s74mgds6JaZk=; b=avizhTII9ZqhaLM3QvP2J8zGOYJxaPUn57gdwTSirHqKUoYSDQLt1Ycl Mf4XsiFQjByOpllrZrCHtY0FD/XI8jMzi9e5wyvXQboxMhVFJuwP1H7hl moeLthI9L3wkkIjxGUIDjbb/9BHB99RSvGNeo8wmfvcE1qKZnh91FAw3V Y=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-02.qualcomm.com with ESMTP; 12 Aug 2021 06:09:25 -0700 X-QCInternal: smtphost Received: from vu-tsimpson-aus.qualcomm.com (HELO vu-tsimpson1-aus.qualcomm.com) ([10.222.150.1]) by ironmsg05-sd.qualcomm.com with ESMTP; 12 Aug 2021 06:09:24 -0700 Received: by vu-tsimpson1-aus.qualcomm.com (Postfix, from userid 47164) id 7B90E91D; Thu, 12 Aug 2021 08:09:24 -0500 (CDT) From: Taylor Simpson To: qemu-devel@nongnu.org Subject: [PATCH] Hexagon (disas/hexagon.c) fix memory leak for early exit cases Date: Thu, 12 Aug 2021 08:09:20 -0500 Message-Id: <1628773760-870-1-git-send-email-tsimpson@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Received-SPF: pass client-ip=199.106.114.39; envelope-from=tsimpson@qualcomm.com; helo=alexa-out-sd-02.qualcomm.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't allocate the string until error conditions have been checked Fixes: a00cfed0e ("Hexagon (disas) disassembler") Eliminate Coverity CID 1460121 (Resource leak) Signed-off-by: Taylor Simpson Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- disas/hexagon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/disas/hexagon.c b/disas/hexagon.c index 3c24e2a..c1a4ffc 100644 --- a/disas/hexagon.c +++ b/disas/hexagon.c @@ -33,7 +33,7 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info) { uint32_t words[PACKET_WORDS_MAX]; bool found_end = false; - GString *buf = g_string_sized_new(PACKET_BUFFER_LEN); + GString *buf; int i, len; for (i = 0; i < PACKET_WORDS_MAX && !found_end; i++) { @@ -57,6 +57,7 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info) return PACKET_WORDS_MAX * sizeof(uint32_t); } + buf = g_string_sized_new(PACKET_BUFFER_LEN); len = disassemble_hexagon(words, i, memaddr, buf); (*info->fprintf_func)(info->stream, "%s", buf->str); g_string_free(buf, true);