app/crypto-perf: fix test file memory leak

Message ID 20230310132017.6900-1-ciara.power@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series app/crypto-perf: fix test file memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Power, Ciara March 10, 2023, 1:20 p.m. UTC
  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: stable@dpdk.org

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 app/test-crypto-perf/cperf_options_parsing.c     | 1 +
 app/test-crypto-perf/cperf_test_vector_parsing.c | 1 +
 2 files changed, 2 insertions(+)
  

Comments

Akhil Goyal March 11, 2023, 7:02 p.m. UTC | #1
> 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: stable@dpdk.org
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

Applied to dpdk-next-crypto
  
Ji, Kai March 13, 2023, 10:21 a.m. UTC | #2
Acked-by: Kai Ji <kai.ji@intel.com>

> -----Original Message-----
> From: Power, Ciara <ciara.power@intel.com>
> Sent: Friday, March 10, 2023 1:20 PM
> To: dev@dpdk.org
> Cc: Ji, Kai <kai.ji@intel.com>; Power, Ciara <ciara.power@intel.com>;
> stable@dpdk.org
> 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: stable@dpdk.org
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
>  app/test-crypto-perf/cperf_options_parsing.c     | 1 +
>  app/test-crypto-perf/cperf_test_vector_parsing.c | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-
> crypto-perf/cperf_options_parsing.c
> index 8c9f632590..26136a52ae 100644
> --- a/app/test-crypto-perf/cperf_options_parsing.c
> +++ b/app/test-crypto-perf/cperf_options_parsing.c
> @@ -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;
>  }
> diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-
> crypto-perf/cperf_test_vector_parsing.c
> index 98e46c3381..737d61d4af 100644
> --- a/app/test-crypto-perf/cperf_test_vector_parsing.c
> +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
> @@ -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
  

Patch

diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c
index 8c9f632590..26136a52ae 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -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;
 }
diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index 98e46c3381..737d61d4af 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -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);