Skip to content

Commit 336bb55

Browse files
committed
Fix crashing
1 parent 7646eb8 commit 336bb55

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/rcl_action_goal_bindings.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ Napi::Value ActionAcceptNewGoal(const Napi::CallbackInfo& info) {
3535
rcl_action_goal_info_t* buffer = reinterpret_cast<rcl_action_goal_info_t*>(
3636
info[1].As<Napi::Buffer<char>>().Data());
3737

38-
rcl_action_goal_handle_t* goal_handle =
39-
reinterpret_cast<rcl_action_goal_handle_t*>(
40-
malloc(sizeof(rcl_action_goal_handle_t)));
41-
42-
goal_handle = rcl_action_accept_new_goal(action_server, buffer);
43-
if (!goal_handle) {
38+
rcl_action_goal_handle_t* new_goal =
39+
rcl_action_accept_new_goal(action_server, buffer);
40+
if (!new_goal) {
4441
Napi::Error::New(env, rcl_get_error_string().str)
4542
.ThrowAsJavaScriptException();
4643
rcl_reset_error();
4744
return env.Undefined();
4845
}
4946

47+
rcl_action_goal_handle_t* goal_handle =
48+
reinterpret_cast<rcl_action_goal_handle_t*>(
49+
malloc(sizeof(rcl_action_goal_handle_t)));
50+
*goal_handle = *new_goal;
5051
auto js_obj =
5152
RclHandle::NewInstance(env, goal_handle, nullptr, [](void* ptr) {
5253
rcl_action_goal_handle_t* goal_handle =

0 commit comments

Comments
 (0)