aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorBill Fischofer <bill.fischofer@linaro.org>2017-02-02 18:28:00 -0600
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-02-10 00:13:16 +0300
commitf59d87a65cf1d08f8715a01dceeaf370a29e51f3 (patch)
treed047132b2c6d16939091df79989b30ba30a0e42b /helper
parent3528ca70668da492a2f1fe85c167b2024406dd8d (diff)
helper: cuckootable: avoid storage leaks on error paths
Ensure that malloced storage areas are freed on error paths. This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2830 Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper')
-rw-r--r--helper/test/cuckootable.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/helper/test/cuckootable.c b/helper/test/cuckootable.c
index 002e52e0a..be655911f 100644
--- a/helper/test/cuckootable.c
+++ b/helper/test/cuckootable.c
@@ -453,10 +453,15 @@ static int test_performance(int number)
unsigned key_num = key_len * elem_num;
key_space = (uint8_t *)malloc(key_num);
- key_ptr = (const void **)malloc(sizeof(void *) * elem_num);
if (key_space == NULL)
return -ENOENT;
+ key_ptr = (const void **)malloc(sizeof(void *) * elem_num);
+ if (key_ptr == NULL) {
+ free(key_space);
+ return -ENOENT;
+ }
+
for (j = 0; j < key_num; j++) {
key_space[j] = rand() % 255;
if (j % key_len == 0)
@@ -473,6 +478,8 @@ static int test_performance(int number)
"performance_test", PERFORMANCE_CAPACITY, key_len, 0);
if (table == NULL) {
printf("cuckoo table creation failed\n");
+ free(key_ptr);
+ free(key_space);
return -ENOENT;
}