From 281a9a28d20b82a1e0e5228c537e451a14450459 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Wed, 19 Jan 2022 16:54:43 +0100
Subject: [PATCH] Prevent memory leak

---
 cmp_tool.c         | 4 ++--
 lib/cmp_tool_lib.c | 6 +-----
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/cmp_tool.c b/cmp_tool.c
index 5ae3061..24587f6 100755
--- a/cmp_tool.c
+++ b/cmp_tool.c
@@ -358,7 +358,7 @@ int main(int argc, char **argv)
 
 			printf("Importing compressed data file %s ... ", data_file_name);
 			buf_size = size = read_file_cmp_entity(data_file_name,
-							     NULL, 0, 0);
+							       NULL, 0, 0);
 			if (size < 0)
 				goto fail;
 			/* to be save allocate at least the size of the cmp_entity struct */
@@ -384,7 +384,7 @@ int main(int argc, char **argv)
 				print_cmp_info(&info);
 
 			/* we reuse the entity buffer for the compressed data */
-			cmp_data_adr = (uint32_t *)ent;
+			cmp_data_adr = (uint32_t *)decomp_input_buf;
 			size = cmp_ent_get_cmp_data(ent, cmp_data_adr, buf_size);
 			ent = NULL;
 			if (size < 0)
diff --git a/lib/cmp_tool_lib.c b/lib/cmp_tool_lib.c
index 093bf65..6028d00 100644
--- a/lib/cmp_tool_lib.c
+++ b/lib/cmp_tool_lib.c
@@ -96,11 +96,7 @@ static FILE *open_file(const char *dirname, const char *filename)
 	}
 
 	errno = 0;
-	pathname = (char *) malloc((size_t)n + 1);
-	if (!pathname) {
-		perror("malloc failed");
-		abort();
-	}
+	pathname = (char *) alloca((size_t)n + 1);
 
 	errno = 0;
 	n = snprintf(pathname, (size_t)n + 1, "%s%s", dirname, filename);
-- 
GitLab