check for alloc failure when copying argv (#68)

This commit is contained in:
William Woodall 2016-08-30 15:36:59 -07:00 committed by GitHub
parent 03900d6af9
commit 9c97489c53

View file

@ -95,6 +95,11 @@ rcl_init(int argc, char ** argv, rcl_allocator_t allocator)
int i;
for (i = 0; i < argc; ++i) {
__rcl_argv[i] = (char *)__rcl_allocator.allocate(strlen(argv[i]), __rcl_allocator.state);
if (!__rcl_argv[i]) {
RCL_SET_ERROR_MSG("allocation failed");
fail_ret = RCL_RET_BAD_ALLOC;
goto fail;
}
memcpy(__rcl_argv[i], argv[i], strlen(argv[i]));
}
rcl_atomic_store(&__rcl_instance_id, ++__rcl_next_unique_id);