From patchwork Tue Oct 31 14:43:59 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: 739578 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1688420wrt; Tue, 31 Oct 2023 07:47:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKO4oGinvl8UwMW2S1+HLy/tgkCWNEp48Jq4LaJ0AlrU/d7wfUORjj2gWG0BbqgCEzRV2c X-Received: by 2002:a1f:1787:0:b0:495:3d9d:535c with SMTP id 129-20020a1f1787000000b004953d9d535cmr11550728vkx.4.1698763662403; Tue, 31 Oct 2023 07:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698763662; cv=none; d=google.com; s=arc-20160816; b=Z4a+hB1sAkpgLObTPggIObctNSWIDZT3fVcMWeCqYM3lVK4b5QzIGgugB7ZS0cih/t mqprioV8NKO/QtIdOh0SnkxF4c2BDy3jkPJv9VGQfIQ2EGUfoV/AhreO2eozZTl4Kvn9 nsQmOW3rCqYq9DzTTYf95bA3HgfwDl2yubh6tAdn6J0zmGMlm0yfKUTms/tnBz0DDPkh pMUt7Khbq13ImH6qaJYyHpx6QCearu5xh81CBH0z9tcwxr37cMhU7I9dyU69bXEqsZ2k Oz+dHDxOtm+YJz9fq5Fa+wrBpf2BTmDCoPnmuzRiqYOLlZCdVJH6SO1skfNQLg8tN1Mz 4cyw== 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=1qbOhazxvRm+dj6LmIpa3iG/xAEISl7lgrvcn9urKP4=; fh=T34aL4dDb6pW7HFZVEwzWmjbo6Ml3Zgquw2siC7JNxc=; b=yXVJlIjJUqs8raeNue9o3BCvwkSaTrcARBvQ5iNYROa5V1aGmoA5Ut8Od00PkZrdgI EoYNw6Kbm63X5gcHyuh0cLTBLPKx/7IF90o5RbIzapKe0qezsyEDo+seYr5jh0Zw6+iR CuV1xdJi07RMt/L0Mjyw+aO/SPJIticxdypv+NZvgLI25lDCGnnkFTBTR7MXmwJAso2G a/Pe4IuScRkJzyO4LSU58Ih308HBaEqgDIMOpxBiPMuf/A51viKGIv8+CUeWAXD6eqgk gc/UgeGQmbB6blCgyfnotb8KIfhJpZaAqvjCFCrJATdpE7P5QDl3DFQDMkaHy4WLzwU5 Q8VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MKJItzpl; 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 f18-20020ac87f12000000b00418122a226dsi1203835qtk.159.2023.10.31.07.47.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Oct 2023 07:47:42 -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=MKJItzpl; 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 1qxpyf-0004tS-IV; Tue, 31 Oct 2023 10:44:21 -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 1qxpyd-0004sN-Cc for qemu-devel@nongnu.org; Tue, 31 Oct 2023 10:44:19 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxpyb-0002Cx-O7 for qemu-devel@nongnu.org; Tue, 31 Oct 2023 10:44:19 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-32f8441dfb5so1691756f8f.0 for ; Tue, 31 Oct 2023 07:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698763456; x=1699368256; 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=1qbOhazxvRm+dj6LmIpa3iG/xAEISl7lgrvcn9urKP4=; b=MKJItzplfXKlre/AAi14zwIUHJWWfDYieklHmTVLk7TEGgU74llGPnGsr7dYAtHkV8 v0SK+6hPB8MHVAhbTQtMtU5xO3cAEn9+V+pE0+oNjN2zSq+CHjQ3TqOuJG8r3+0MgpKQ ARiDRETpFqApPgXeBSmaZ0DxES1m0BYn18qp7KK6uZbAVG+SIieN6iObvmlNJZ0rJTWF 6LqX6ITudMRrNuE+bI4HSHr+6HMSdUk3jXt/+ZbH7CGT0f10R1oTu+ahrel0Wj450upM NRiJqWW+BcuEX57ycKYWpYhJsuIrzYL2eYze1ujheAZPlWa/dZMA+qEUxMxWDnOozust yRsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698763456; x=1699368256; 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=1qbOhazxvRm+dj6LmIpa3iG/xAEISl7lgrvcn9urKP4=; b=nx95+v17e4fga53EUKRS7Mwlz2ElmGvHT7hTvE2Mn+oZBVWNOydPgBjpAuntYUHUbe RQFMLOGKgJrZPVl1WxnGH7xv6HAvfKPHatXE6+TfY+tvuJdE04jP68RbU0Si3Yj7OuTG MHgnHO5831vm00deUR6DIa7zD5SM98H/Uk5N6KsCvR1Fg9Iy4XN9jXwNkMNp4xrkQx1r UdGnRc3c+2ppjWK2g/q1RHu9gYIY5uX7JLkjYCbzLWzSKnyANSn59axZ4Dw9pEV5xHXM qsjAvQKjTSamiS7SU6DdAGYAqxRdM1o7Olz1qo9W5SsXhE3paLNI+fVNTESHXm41EKwS Bmpw== X-Gm-Message-State: AOJu0Yy+Qmm6aIZzgUnyQrBFtZkzDaUGvcVVFK2fwQv9HX75/3dBUTEt niQ8/QPRLOsWPTsRzxtIWbw1dQ== X-Received: by 2002:a05:6000:2a9:b0:32f:7cea:2ea2 with SMTP id l9-20020a05600002a900b0032f7cea2ea2mr9626642wry.17.1698763456291; Tue, 31 Oct 2023 07:44:16 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g9-20020adffc89000000b0032da8fb0d05sm1649917wrr.110.2023.10.31.07.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 07:44:12 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 68AFC65730; Tue, 31 Oct 2023 14:44:03 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Matheus Tavares Bernardino , =?utf-8?q?Philip?= =?utf-8?q?pe_Mathieu-Daud=C3=A9?= , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= Subject: [PULL 17/19] semihosting: fix memleak at semihosting_arg_fallback Date: Tue, 31 Oct 2023 14:43:59 +0000 Message-Id: <20231031144401.1238210-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231031144401.1238210-1-alex.bennee@linaro.org> References: <20231031144401.1238210-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: <20231029145033.592566-18-alex.bennee@linaro.org> 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, " ");