Skip to content

Commit

Permalink
cc_array and cc_ring_array NULL fixes (twitter#201)
Browse files Browse the repository at this point in the history
* cc_array fix NULL pointer check

* cc_ring_array fix NULL dereference

- log_verb() would result with segfault if arr=NULL
  • Loading branch information
michalbiesek authored and Yao Yue committed Jul 20, 2019
1 parent 1c8df42 commit e58f6a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cc_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ array_create(struct array **arr, uint32_t nalloc, size_t size)
ASSERT(nalloc != 0 && size != 0);

*arr = (struct array *)cc_alloc(sizeof(**arr));
if (arr == NULL) {
if (*arr == NULL) {
log_info("array creation failed due to OOM");

return CC_ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions src/cc_ring_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ ring_array_create(size_t elem_size, uint32_t cap)
void
ring_array_destroy(struct ring_array **arr)
{
log_verb("destroying ring array %p and freeing memory", *arr);

if ((arr == NULL) || (*arr == NULL)) {
log_warn("destroying NULL ring_array pointer");
return;
}

log_verb("destroying ring array %p and freeing memory", *arr);

cc_free(*arr);
*arr = NULL;
}

0 comments on commit e58f6a8

Please sign in to comment.