diff mbox series

[ima-evm-utils,v1,2/4] Fix memory leak related to entry.template

Message ID 20221102184534.1075049-3-stefanb@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Fix some issues in evmctl | expand

Commit Message

Stefan Berger Nov. 2, 2022, 6:45 p.m. UTC
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/evmctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/evmctl.c b/src/evmctl.c
index c2fe152..4afc265 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2095,7 +2095,7 @@  static int ima_measurement(const char *file)
 	unsigned long entry_num = 0;
 	int c;
 
-	struct template_entry entry = { .template = 0 };
+	struct template_entry entry = { .template = NULL };
 	FILE *fp;
 	int invalid_template_digest = 0;
 	int err_padded = -1;
@@ -2206,6 +2206,10 @@  static int ima_measurement(const char *file)
 			free(entry.template);
 			entry.template_buf_len = entry.template_len;
 			entry.template = malloc(entry.template_len);
+			if (!entry.template) {
+				log_err("Out of memory\n");
+				goto out;
+			}
 		}
 
 		if (!is_ima_template) {
@@ -2325,6 +2329,7 @@  out_free:
 	free(tpm_banks);
 	free(pseudo_banks);
 	free(pseudo_padded_banks);
+	free(entry.template);
 
 	return err;
 }