From patchwork Tue May 15 19:02:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 159414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 95A5AB6FAA for ; Wed, 16 May 2012 05:02:58 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUN1M-0004yE-2m for incoming@patchwork.ozlabs.org; Tue, 15 May 2012 19:02:56 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUN1J-0004xS-VA for fwts-devel@lists.ubuntu.com; Tue, 15 May 2012 19:02:54 +0000 Received: from cpc19-craw6-2-0-cust5.croy.cable.virginmedia.com ([77.102.228.6] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1SUN1J-0007Hu-OC for fwts-devel@lists.ubuntu.com; Tue, 15 May 2012 19:02:53 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] pci: aspm: free memory from lists Date: Tue, 15 May 2012 20:02:52 +0100 Message-Id: <1337108572-4455-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King free lspci text lists and pci device lists correctly. valgrind found a bunch of memory allocations that were not being freed. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- src/pci/aspm/aspm.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/pci/aspm/aspm.c b/src/pci/aspm/aspm.c index c461ce8..fe6cb60 100644 --- a/src/pci/aspm/aspm.c +++ b/src/pci/aspm/aspm.c @@ -188,6 +188,17 @@ int pcie_compare_rp_dev_aspm_registers(fwts_framework *fw, return ret; } +static void pci_device_list_free(struct pci_device *head) +{ + struct pci_device *next; + + while (head) { + next = head->next; + free(head); + head = next; + } +} + int pcie_check_aspm_registers(fwts_framework *fw, const fwts_log_level level) { @@ -212,8 +223,11 @@ int pcie_check_aspm_registers(fwts_framework *fw, char *pEnd; device = (struct pci_device *) calloc(1, sizeof(*device)); - if (device == NULL) + if (device == NULL) { + pci_device_list_free(head); + fwts_text_list_free(lspci_output); return FWTS_ERROR; + } device->bus = strtol(line, &pEnd, 16); device->dev = strtol(pEnd + 1, &pEnd, 16); @@ -226,6 +240,7 @@ int pcie_check_aspm_registers(fwts_framework *fw, cur = device; } + fwts_text_list_free(lspci_output); for (cur = head; cur; cur = cur->next) { int reg_loc = 0, reg_val = 0; @@ -235,10 +250,13 @@ int pcie_check_aspm_registers(fwts_framework *fw, fw->lspci, cur->bus, cur->dev, cur->func); if (fwts_pipe_exec(command, &lspci_output) == FWTS_EXEC_ERROR) { fwts_log_warning(fw, "Could not execute %s", command); + pci_device_list_free(head); return FWTS_ERROR; } - if (lspci_output == NULL) + if (lspci_output == NULL) { + pci_device_list_free(head); return FWTS_ERROR; + } fwts_list_foreach(item, lspci_output) { char *line = fwts_text_list_text(item); @@ -253,6 +271,7 @@ int pcie_check_aspm_registers(fwts_framework *fw, } } } + fwts_text_list_free(lspci_output); } /* Check aspm registers from the list of pci devices */ @@ -275,14 +294,7 @@ int pcie_check_aspm_registers(fwts_framework *fw, } } - cur = head; - while (cur != NULL) { - device = cur->next; - free(cur); - cur = device; - } - - fwts_text_list_free(lspci_output); + pci_device_list_free(head); return ret; }