[PATCH] bios: mtrr: fix memory leak on mtrr entries

Colin King colin.king at canonical.com
Thu May 14 11:33:01 UTC 2015


From: Colin Ian King <colin.king at canonical.com>

CoverityScan picked up a memory leak on the allocated entries that
don't get added to the mttr entry list when they fail specific
filtering criteria.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/bios/mtrr/mtrr.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
index 8bec28b..c86090f 100644
--- a/src/bios/mtrr/mtrr.c
+++ b/src/bios/mtrr/mtrr.c
@@ -119,18 +119,24 @@ static int get_mtrrs(void)
 		 */
 
 		/* Get register, in decimal  */
-		if (strncmp(line, "reg", 3))
+		if (strncmp(line, "reg", 3)) {
+			free(entry);
 			continue;
+		}
 		entry->reg = strtoul(line + 3, NULL, 10);
 
 		/* Get base, in hex */
-		if ((ptr1 = strstr(line, "base=0x")) == NULL)
+		if ((ptr1 = strstr(line, "base=0x")) == NULL) {
+			free(entry);
 			continue;
+		}
 		entry->start = strtoull(ptr1 + 5, NULL, 16);
 
 		/* Get size, in decimal */
-		if ((ptr1 = strstr(line, "size=")) == NULL)
+		if ((ptr1 = strstr(line, "size=")) == NULL) {
+			free(entry);
 			continue;
+		}
 
 		entry->size = strtoull(ptr1 + 5, &ptr2, 10);
 		if (ptr2 && (*ptr2 == 'm'))
-- 
2.1.4




More information about the fwts-devel mailing list