From nobody Sun May 19 21:29:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@quicinc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=quicinc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628824115918183.77823978666322; Thu, 12 Aug 2021 20:08:35 -0700 (PDT) Received: from localhost ([::1]:43702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mENYg-0007iw-Fb for importer@patchew.org; Thu, 12 Aug 2021 23:08:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mENXo-0006LA-5g for qemu-devel@nongnu.org; Thu, 12 Aug 2021 23:07:40 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:34261) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1mENXj-0007iJ-8e for qemu-devel@nongnu.org; Thu, 12 Aug 2021 23:07:39 -0400 Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-02.qualcomm.com with ESMTP; 12 Aug 2021 20:07:32 -0700 Received: from vu-tsimpson-aus.qualcomm.com (HELO vu-tsimpson1-aus.qualcomm.com) ([10.222.150.1]) by ironmsg-SD-alpha.qualcomm.com with ESMTP; 12 Aug 2021 20:07:32 -0700 Received: by vu-tsimpson1-aus.qualcomm.com (Postfix, from userid 47164) id 8DF9ECAF; Thu, 12 Aug 2021 22:07:31 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1628824055; x=1660360055; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gS6qhv1h5ZW5RzLHKmg10lU2gHLCnwVsTTokS3iHrLM=; b=ei2WwBmBhmSNbZcV0DSJB4d5Wv6cKja0EyX2v9vSczymBjHT/W2vAWbV m/iDHsistkLeXB9z59taLZzDQNSz1R1SRvBoVFbnP+VEWaIDFRNzxy79s NJ1kUPgQYXyddZu10cT2Hxy8QlHH2t5b6xzUbLHdIbxIZiSN6CQ4fXLl0 A=; X-QCInternal: smtphost From: Taylor Simpson To: qemu-devel@nongnu.org Subject: [PULL 1/1] Hexagon (disas/hexagon.c) fix memory leak for early exit cases Date: Thu, 12 Aug 2021 22:07:30 -0500 Message-Id: <1628824050-15249-2-git-send-email-tsimpson@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1628824050-15249-1-git-send-email-tsimpson@quicinc.com> References: <1628824050-15249-1-git-send-email-tsimpson@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628824117789100001 Don't allocate the string until error conditions have been checked Fixes: a00cfed0e ("Hexagon (disas) disassembler") Eliminate Coverity CID 1460121 (Resource leak) Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud? Signed-off-by: Taylor Simpson --- 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 disassembl= e_info *info) { uint32_t words[PACKET_WORDS_MAX]; bool found_end =3D false; - GString *buf =3D g_string_sized_new(PACKET_BUFFER_LEN); + GString *buf; int i, len; =20 for (i =3D 0; i < PACKET_WORDS_MAX && !found_end; i++) { @@ -57,6 +57,7 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassembl= e_info *info) return PACKET_WORDS_MAX * sizeof(uint32_t); } =20 + buf =3D g_string_sized_new(PACKET_BUFFER_LEN); len =3D disassemble_hexagon(words, i, memaddr, buf); (*info->fprintf_func)(info->stream, "%s", buf->str); g_string_free(buf, true); --=20 2.7.4