From patchwork Sun Oct 29 14:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 739061 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp743100wrt; Sun, 29 Oct 2023 07:53:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAT/wdyv1ffSLD9K5P7StmZr1wyB8OyXL3kux3ffWtPRQrTXFo79mso/0E24FVdcfipMjG X-Received: by 2002:a05:622a:249:b0:418:224:db06 with SMTP id c9-20020a05622a024900b004180224db06mr9703520qtx.50.1698591217766; Sun, 29 Oct 2023 07:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698591217; cv=none; d=google.com; s=arc-20160816; b=tt9CHt3CohfaFUvnaGpmZslhPgdh0FQxhrT0vKLWbdZaTlSrA0xg1u0Bsk+vtYWVJ3 kAmEeDqznJPHxBsubKUiFN3KyMm3Ojytjq/gk2qknXBKgqwQ3it8jUghyBEq0qVjPKix SE4R6c7deOJO1uLmCwPwdbuXFJZZCpJh/b+YOYOofyw838pjReCbuS2jz/hFQOMVMW8u AkFIWibtikRvnQQsYP5tpxqq0y8SqpIvvgYfDOfNeYefgfonW8Lcsx8x9VULBWISsO8v bCZjF7e+6Mc+yh4gJfRjuDz99Ele9ZjQ/pZa0ttl1eIfIZo7qL0VpDDgZkv2/PF9xswK G9Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L7mkLliNPzNXB/MT8B2nzmAQfKs62ilya+P57Y1l0Y4=; fh=/isM2HmBPQmFjHtW5wiM7yJZHDb4I8SRZCvND/w1ajg=; b=fh0rcFl4c/JJnE+HzjTP+5sMTEEA+ZEGLTgRY0jZr1OD0gAYpuBKCc7H4bUBKvw8Td 4sZLWsHTdczOL6HhOlAf0k5cAy49fV73kXuPoopUhFM74hPTGYyAtucTW02XUDiJk6ge XzAj8RRRUlKvfFjudK4jdG1xnLz2hv2S61XQ8G7uIivN5Qd7Zx8p7QsN+xCxcN0CGe2d uz1BRkcSczPYPfheUhLjPHexmYHpuWqmkUGujf79IaXXPvMY+p+jP3zFyli21rzcZPeO vizH9wgzA+ez4+6hyWP/hPBhiemVnVwaYwxxdRsqDh+6Rf+eS4ptwbb8We38PCKeeiIu gqIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X63nzoop; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o17-20020a05622a139100b0041cc3fd51a3si3944589qtk.13.2023.10.29.07.53.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Oct 2023 07:53:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X63nzoop; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qx77r-0007bS-Ta; Sun, 29 Oct 2023 10:50:51 -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 1qx77p-0007Yb-Po for qemu-devel@nongnu.org; Sun, 29 Oct 2023 10:50:49 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qx77j-00058d-VX for qemu-devel@nongnu.org; Sun, 29 Oct 2023 10:50:49 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4083f61312eso28756635e9.3 for ; Sun, 29 Oct 2023 07:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698591042; x=1699195842; 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=L7mkLliNPzNXB/MT8B2nzmAQfKs62ilya+P57Y1l0Y4=; b=X63nzoope1lqBtmKUIradv/fto8GCmQHWr3Ft6jvfemAcJMyFjmQqhvExSQpOwt5W6 n+529jkrpNLU/mRi28AKIvP+Ck5AQepnb4Ct2/u3FE3HXZ2ePXkbsnPHWz6BmPN8M5nw +VJO4Y6GAdsHatgwvzY43IV/FBjBsIXs7QMxUSUuSKs7JjCI2GOJSXgmiDBJFOrhvwAe UyIia5V99fn9yMNuiAoa8zY04iBcxqcddrOwqmL8VMhA6pLTYldaK14F9hisaLKZuWPd reezKRy5nf5VTpulgOIn8W1WkArm5lnTIarozSi8+ZJBC2Szs3/fe5MZCaH4GMLL/JBa 6Omw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698591042; x=1699195842; 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=L7mkLliNPzNXB/MT8B2nzmAQfKs62ilya+P57Y1l0Y4=; b=L1zVfmq/fLww+4Ljm9o/DXKZcr2kQ6/CNJZXgD5NqO2gX15de8sRBnzOk7NDWpbaf1 6hvS01o7ZmwcVGG+uFjkRs2CTfn4sJRjwXKzIkHwUAXM+cqaH+NN15/JdCL5Y9/3lL4k cdmxpV/CYQ3htUApB+VQKDytIDMelwhJTZr4vIVRrhHNGxw7y0I6iLavswFoU53UjZsg DQUOdwHHjKGlQXGqxqpBz49HLVKnaM9ePSiAe2m0dANkmc1mO3rU+wNkRlr6HueoJ5iM bVgLHKlW3XAfFyo6dA9yM3wXdgtizPNwnWLoo1AsNHMBGvXxG+2VCDZda5+rlW2+3Nq2 SlYg== X-Gm-Message-State: AOJu0YxIIKZ8V+It3S12t2bxYDMdAd0a5l1Npw2Yh+R0qtdFDzVXpuXF ttiJwc1xlG5bGAsHyvN7dmosmA== X-Received: by 2002:a5d:6851:0:b0:321:4c58:7722 with SMTP id o17-20020a5d6851000000b003214c587722mr6759021wrw.69.1698591042147; Sun, 29 Oct 2023 07:50:42 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id w7-20020a5d6807000000b0032008f99216sm6044787wru.96.2023.10.29.07.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 07:50:40 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B100865709; Sun, 29 Oct 2023 14:50:35 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Paolo Bonzini , Mahmoud Mandour , Wainer dos Santos Moschetta , Brad Smith , Aleksandar Rikalo , Kyle Evans , Aurelien Jarno , Jiaxun Yang , qemu-arm@nongnu.org, Peter Maydell , Thomas Huth , Warner Losh , "Edgar E. Iglesias" , Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Beraldo Leal , Brian Cain , Alexandre Iooss , Matheus Tavares Bernardino Subject: [PATCH v2 17/19] semihosting: fix memleak at semihosting_arg_fallback Date: Sun, 29 Oct 2023 14:50:31 +0000 Message-Id: <20231029145033.592566-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231029145033.592566-1-alex.bennee@linaro.org> References: <20231029145033.592566-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é Message-Id: <03d81c56bfc3d08224e4106efca5949d8894cfa5.1697801632.git.quic_mathbern@quicinc.com> Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20231028103311.347104-16-alex.bennee@linaro.org> --- 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 = g_strdup(cmd); /* argv[0] */ add_semihosting_arg(&semihosting, "arg", file, NULL); /* split -append and initialize argv[1..n] */ - cmd_token = strtok(g_strdup(cmd), " "); + cmd_token = strtok(cmd_dup, " "); while (cmd_token) { add_semihosting_arg(&semihosting, "arg", cmd_token, NULL); cmd_token = strtok(NULL, " ");