Skip to content

Commit

Permalink
[C] Style change to be more explicit on allocation behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Apr 11, 2024
1 parent 93227ce commit afde3db
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions aeron-client/src/main/c/aeron_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,31 @@

int aeron_alloc_no_err(void **ptr, size_t size)
{
*ptr = malloc(size);

if (NULL == *ptr)
void *bytes = malloc(size);
if (NULL == bytes)
{
*ptr = NULL;
return -1;
}

memset(*ptr, 0, size);
memset(bytes, 0, size);
*ptr = bytes;

return 0;
}

int aeron_alloc(void **ptr, size_t size)
{
*ptr = malloc(size);

if (NULL == *ptr)
void *bytes = malloc(size);
if (NULL == bytes)
{
*ptr = NULL;
AERON_SET_ERR(ENOMEM, "Failed to allocate %" PRIu64 " bytes", (uint64_t)size);
return -1;
}

memset(*ptr, 0, size);
memset(bytes, 0, size);
*ptr = bytes;

return 0;
}
Expand Down

0 comments on commit afde3db

Please sign in to comment.