Skip to contentSkip to conversation

app/crypto-perf: fix test file memory leak

PATCH Applied Ciara Power 3 participants 3 messages Mar 10, 2023 – Mar 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/crypto-perf: fix test file memory leak

A memory leak was detected using the AddressSanitizer tool, when running the crypto-perf application with a test vector file.

The strdup function used returns a pointer to a null-terminated byte string, which must be freed after use. This patch frees the pointer in an error case, and also after a successful run.

Fixes f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
---
 app/test-crypto-perf/cperf_options_parsing.c     | 1 +
 app/test-crypto-perf/cperf_test_vector_parsing.c | 1 +
 2 files changed, 2 insertions(+)
app/test-crypto-perf/cperf_options_parsing.c +1 -0
index 8c9f632590..26136a52ae 100644
@@ -519,6 +519,7 @@ parse_test_file(struct cperf_options *opts,
 	if (access(opts->test_file, F_OK) != -1)
 		return 0;
 	RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
+	free(opts->test_file);
 
 	return -1;
 }
app/test-crypto-perf/cperf_test_vector_parsing.c +1 -0
index 98e46c3381..737d61d4af 100644
@@ -30,6 +30,7 @@ free_test_vector(struct cperf_test_vector *vector, struct cperf_options *opts)
 		rte_free(vector->cipher_key.data);
 		rte_free(vector->auth_key.data);
 		rte_free(vector->ciphertext.data);
+		free(opts->test_file);
 	}
 
 	rte_free(vector);
Signature · 1 line
2.25.1
Acked-by on v1 1/1 Applied
#1 lore raw
Quoted 7 lines

A memory leak was detected using the AddressSanitizer tool, when running the crypto-perf application with a test vector file.

The strdup function used returns a pointer to a null-terminated byte string, which must be freed after use. This patch frees the pointer in an error case, and also after a successful run.

Quoted 5 lines
Fixes f8be1786b1b8 ("app/crypto-perf: introduce performance test

application")
Cc: [email protected]

Applied to dpdk-next-crypto

Acked-by on v1 1/1
#2 lore raw
In reply to Ciara Power
Quoted 54 lines

-----Original Message-----
From: Power, Ciara <[email protected]>
Sent: Friday, March 10, 2023 1:20 PM
To: [email protected]
Cc: Ji, Kai <[email protected]>; Power, Ciara <[email protected]>; [email protected]
Subject: [PATCH] app/crypto-perf: fix test file memory leak

A memory leak was detected using the AddressSanitizer tool, when running the crypto-perf application with a test vector file.

The strdup function used returns a pointer to a null-terminated byte string, which must be freed after use. This patch frees the pointer in an error case, and also after a successful run.

Fixes f8be1786b1b8 ("app/crypto-perf: introduce performance test

application")
Cc: [email protected]

---
 app/test-crypto-perf/cperf_options_parsing.c     | 1 +
 app/test-crypto-perf/cperf_test_vector_parsing.c | 1 +
 2 files changed, 2 insertions(+)
app/test- renamed from app/test-crypto-perf/cperf_options_parsing.c +0 -0

crypto-perf/cperf_options_parsing.c
index 8c9f632590..26136a52ae 100644

app/test-crypto-perf/cperf_options_parsing.c +1 -0
@@ -519,6 +519,7 @@ parse_test_file(struct cperf_options *opts,
 	if (access(opts->test_file, F_OK) != -1)
 		return 0;
 	RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
+	free(opts->test_file);
 
 	return -1;
 }
app/test- renamed from app/test-crypto-perf/cperf_test_vector_parsing.c +0 -0

crypto-perf/cperf_test_vector_parsing.c
index 98e46c3381..737d61d4af 100644

app/test-crypto-perf/cperf_test_vector_parsing.c +1 -0
@@ -30,6 +30,7 @@ free_test_vector(struct cperf_test_vector *vector,
 struct cperf_options *opts)
 		rte_free(vector->cipher_key.data);
 		rte_free(vector->auth_key.data);
 		rte_free(vector->ciphertext.data);
+		free(opts->test_file);
 	}
 

rte_free(vector);
--
2.25.1