From patchwork Mon Jan 29 07:17:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ivanhu X-Patchwork-Id: 1892089 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 4TNflW6p1kz23fD for ; Mon, 29 Jan 2024 18:17:59 +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 1rULtt-0006wC-Ss; Mon, 29 Jan 2024 07:17:50 +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 1rULto-0006vj-Q8 for fwts-devel@lists.ubuntu.com; Mon, 29 Jan 2024 07:17:45 +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 D19493F305 for ; Mon, 29 Jan 2024 07:17:43 +0000 (UTC) From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] framework: fix memory leaks caused by fwts_log_get_filenames Date: Mon, 29 Jan 2024 15:17:39 +0800 Message-Id: <20240129071739.61149-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" BUgLink: https://bugs.launchpad.net/fwts/+bug/2051480 Got below resource leak error from the coverity scan *** CID 343913: Resource leaks (RESOURCE_LEAK) /src/lib/src/fwts_framework.c: 1567 in fwts_framework_args() 1561 /* Results log */ 1562 if ((fw->results = fwts_log_open("fwts", 1563 fw->results_logname, 1564 (fw->flags & FWTS_FLAG_FORCE_CLEAN) ? "w" : "a", 1565 fw->log_type)) == NULL) { 1566 ret = FWTS_ERROR; >>> CID 343913: Resource leaks (RESOURCE_LEAK) >>> Failing to save or free storage allocated by "fwts_log_get_filenames(fw->results_logname, fw->log_type)" leaks it. 1567 fprintf(stderr, "%s: Cannot open results log '%s'" 1568 " (you may need to remove it to set proper" 1569 " permissions).\n", 1570 argv[0], 1571 fwts_log_get_filenames(fw->results_logname, fw->log_type)); 1572 goto tidy_close; Signed-off-by: Ivan Hu --- src/lib/src/fwts_framework.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c index 41124394..b4d3c885 100644 --- a/src/lib/src/fwts_framework.c +++ b/src/lib/src/fwts_framework.c @@ -1563,12 +1563,16 @@ int fwts_framework_args(const int argc, char **argv) fw->results_logname, (fw->flags & FWTS_FLAG_FORCE_CLEAN) ? "w" : "a", fw->log_type)) == NULL) { + char *filenames = fwts_log_get_filenames(fw->results_logname, fw->log_type); + ret = FWTS_ERROR; fprintf(stderr, "%s: Cannot open results log '%s'" " (you may need to remove it to set proper" " permissions).\n", argv[0], - fwts_log_get_filenames(fw->results_logname, fw->log_type)); + filenames ? filenames : fw->results_logname); + if (filenames) + free(filenames); goto tidy_close; }