Message ID | 20170203002802.28881-1-bill.fischofer@linaro.org |
---|---|
State | Accepted |
Commit | f59d87a65cf1d08f8715a01dceeaf370a29e51f3 |
Headers | show |
Series | [1/3] helper: cuckootable: avoid storage leaks on error paths | expand |
Reviewed and merged. Maxim. On 02/03/17 03:28, Bill Fischofer wrote: > 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> > --- > helper/test/cuckootable.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/helper/test/cuckootable.c b/helper/test/cuckootable.c > index 002e52e0..be655911 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; > } > >
diff --git a/helper/test/cuckootable.c b/helper/test/cuckootable.c index 002e52e0..be655911 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; }
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> --- helper/test/cuckootable.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.11.0.295.gd7dffce