From patchwork Fri Jan 26 08:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ivanhu X-Patchwork-Id: 1891186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TLs2S717Hz23fD for ; Fri, 26 Jan 2024 19:54:39 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rTHyj-0007IH-4E; Fri, 26 Jan 2024 08:54:27 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rTHyX-0007Hu-6u for fwts-devel@lists.ubuntu.com; Fri, 26 Jan 2024 08:54:15 +0000 Received: from canonical.com (118-163-61-247.hinet-ip.hinet.net [118.163.61.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 36F663F1FC for ; Fri, 26 Jan 2024 08:54:11 +0000 (UTC) From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] acpi: s3: fix potential memory leaks on fwts_get() calls Date: Fri, 26 Jan 2024 16:54:08 +0800 Message-Id: <20240126085408.42394-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Potential memory leaks when str is not s2idle and NULL. Signed-off-by: Ivan Hu --- src/acpi/s3/s3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c index 903f22f4..ffdb7165 100644 --- a/src/acpi/s3/s3.c +++ b/src/acpi/s3/s3.c @@ -206,10 +206,11 @@ static int s3_init(fwts_framework *fw) str = fwts_get(PM_SUSPEND_PATH); if (str && strstr(str, "[s2idle]")) { strncpy(sleep_type_orig, "s2idle", strlen("s2idle") + 1); - free(str); } else { strncpy(sleep_type_orig, "deep", strlen("deep") + 1); } + if (str) + free(str); if (s3_sleep_type) { fwts_log_info(fw, "Override system suspend default by '%s'\n", s3_sleep_type); @@ -220,10 +221,11 @@ static int s3_init(fwts_framework *fw) str = fwts_get(PM_SUSPEND_PATH); if (str && strstr(str, "[s2idle]")) { strncpy(sleep_type, "s2idle", strlen("s2idle") + 1); - free(str); } else { strncpy(sleep_type, "S3", strlen("S3") + 1); } + if (str) + free(str); str = fwts_get(INTEL_PM_S0IX_WARN); if (str && strstr(str, "N"))