From nobody Wed Nov 27 14:28:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1698489422; cv=none; d=zohomail.com; s=zohoarc; b=BfR3b+SQMca87ernWeoSXWy0mb6GqS5L8Lbjdk244wDFzwNTMOFSRgnRBMLqM7xNrz2CqN5Obh8ipnMnK5n2f5iYmj/j1V6sXyPXq7amTlFu/pndEbJHHpUPv/UUjQ1jvPJmcyQi/TO5qeWGKaoHhXUbUPstr3LeMwjCXRG0VSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698489422; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6LNGgzff5IUOW67edmSf6WpHil0/J68PsVdXi1+Q8NU=; b=j9tHIxh3lKNCIgyPSK+CMyiPRF9N0gpTOUTXzOqZ5qzhOA9c1evzoOGA4Zt+KDf5my9phQ6Wj3mHsH5r3qIKz7k0Nmhse4u11zb9TEwl8AihRo/9QhxAYj8XdUsCuBnGp6pL3FXwZUaZxMO7/c3j5ej3NEZRky27q60g3iRr1ak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698489422844409.07562585474784; Sat, 28 Oct 2023 03:37:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qwgdM-0006LF-C1; Sat, 28 Oct 2023 06:33:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qwgdI-0006JJ-3l for qemu-devel@nongnu.org; Sat, 28 Oct 2023 06:33:32 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qwgd7-0003AT-3q for qemu-devel@nongnu.org; Sat, 28 Oct 2023 06:33:31 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-408382da7f0so21510025e9.0 for ; Sat, 28 Oct 2023 03:33:20 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id iv8-20020a05600c548800b003fefaf299b6sm3769631wmb.38.2023.10.28.03.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 03:33:18 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 799495F7A4; Sat, 28 Oct 2023 11:33:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698489199; x=1699093999; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6LNGgzff5IUOW67edmSf6WpHil0/J68PsVdXi1+Q8NU=; b=cAhvlHv8/XGGz5FAR1Wy+U57JoGYYtFB00dBvgdbNY1WV3E+gLJmDBho08JW2Gbo3M JP6CrwBzMTp53ZEYNZAC3JPB5Lfsl/YXGeWntumMHVvq0DJq5imyk6ADctCpsn0UGyPJ GE+AewbVxrRo/Bkjypud80JD1DQst+s7HG1cWOE6wQu78rnhP0uRY7dT7tAYKo5gxKIS B6NeISMIaFE++iDNErGaDn4FZ50nKRya+OXWjF+fj7iYffJWYaj+JSomSoEWVKbzVaxG EM8gqD8QRF6SNFXj83EUVNae00rdCnxO5J9tjAVDXxEq7DQaldiUQesGW7hgTQ2j4BzY gTMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698489199; x=1699093999; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6LNGgzff5IUOW67edmSf6WpHil0/J68PsVdXi1+Q8NU=; b=A8QOtEfuUzEIOYq+ZCR4hIR3ThumFfSVqcgcb791nKLhKqCxhGTpVsqQiQKeXP4bwj KoaBl5MAHeXk9XgDb61MY9fie+REce1MjQe/clrbJ/3atEDeyApfBsEsKSmaPYFGtjHn HTRjhb+MoW/pdRP5juFSNnR8xGGKh4to+v0tkhHsW6gYTEnd0YWO+3TEFN3cVtCrM81z Rpx0RqimG+bA6N8g7EwivMCK84XzOOCHJEVbBfsw/BfGn07Kv/1fr62+wI8fcrFAh0kT SjvV29q+sI3kj8heowucpfSWXxq5gGnRL/Ko7URe0F+dXgia5HE0nti2QgCGio4vxo7l XS5g== X-Gm-Message-State: AOJu0Yz7klUzG0Nwv6aNAd1MB5F4JZpPqavzGJPXMpWbH3rwfiqzwyUp ZAYJGwYgTha8VcXGBJge77dWxQ== X-Google-Smtp-Source: AGHT+IEdTjOK7YMdz53T3gNzElKCRm+kFK6/aW3jjyCvApr7PUWxuXqXNqCv5QlXYPDzW0+Gl01kuA== X-Received: by 2002:a05:600c:1c23:b0:402:f501:447c with SMTP id j35-20020a05600c1c2300b00402f501447cmr4295481wms.0.1698489199592; Sat, 28 Oct 2023 03:33:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , Mahmoud Mandour , Brian Cain , Paolo Bonzini , Warner Losh , Eduardo Habkost , Alexandre Iooss , "Edgar E. Iglesias" , Kyle Evans , qemu-arm@nongnu.org, Aleksandar Rikalo , Aurelien Jarno , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Wainer dos Santos Moschetta , Peter Maydell , Brad Smith , Jiaxun Yang , Thomas Huth , Matheus Tavares Bernardino Subject: [PATCH 15/17] semihosting: fix memleak at semihosting_arg_fallback Date: Sat, 28 Oct 2023 11:33:09 +0100 Message-Id: <20231028103311.347104-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231028103311.347104-1-alex.bennee@linaro.org> References: <20231028103311.347104-1-alex.bennee@linaro.org> 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=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1698489423487100003 From: Matheus Tavares Bernardino We duplicate "cmd" as strtok may modify its argument, but we forgot to free it later. Furthermore, add_semihosting_arg doesn't take responsibility for this memory either (it strdup's the argument). Signed-off-by: Matheus Tavares Bernardino Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <03d81c56bfc3d08224e4106efca5949d8894cfa5.1697801632.git.quic_m= athbern@quicinc.com> Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- semihosting/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/semihosting/config.c b/semihosting/config.c index 249a377ae8..56283b5c3c 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -113,12 +113,13 @@ static int add_semihosting_arg(void *opaque, void semihosting_arg_fallback(const char *file, const char *cmd) { char *cmd_token; + g_autofree char *cmd_dup =3D g_strdup(cmd); =20 /* argv[0] */ add_semihosting_arg(&semihosting, "arg", file, NULL); =20 /* split -append and initialize argv[1..n] */ - cmd_token =3D strtok(g_strdup(cmd), " "); + cmd_token =3D strtok(cmd_dup, " "); while (cmd_token) { add_semihosting_arg(&semihosting, "arg", cmd_token, NULL); cmd_token =3D strtok(NULL, " "); --=20 2.39.2