Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use rcutils allocator in allocators.c to avoid direct use of malloc/free #140

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rmw/src/allocators.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
#include <stdlib.h>
#include <string.h>

#include <rcutils/allocator.h>

#include "rmw/types.h"

void *
rmw_allocate(size_t size)
{
// Could be overridden with a general purpose allocator
void * ptr = malloc(size);
rcutils_allocator_t allocator = rcutils_get_default_allocator();
void * ptr = allocator.allocate(size, allocator.state);
if (ptr) {
memset(ptr, 0, size);
}
Expand All @@ -34,7 +37,8 @@ void
rmw_free(void * pointer)
{
// Should have a corresponding override with rmw_allocate
free(pointer);
rcutils_allocator_t allocator = rcutils_get_default_allocator();
allocator.deallocate(pointer, allocator.state);
}

rmw_node_t *
Expand Down