Skip to content

Commit 0c94326

Browse files
authored
Call rcl_action_goal_status_array_fini() when publishing status failed (#1332)
This PR improves resource management in the `ActionPublishStatus` function by ensuring `rcl_action_goal_status_array_fini()` is called to clean up the status message array even when publishing the status fails, preventing potential resource leaks. Fix: #1330
1 parent 5e43c92 commit 0c94326

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/rcl_action_server_bindings.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,27 @@ Napi::Value ActionPublishStatus(const Napi::CallbackInfo& info) {
317317
rcl_action_get_goal_status_array(action_server, &status_message),
318318
RCL_RET_OK, rcl_get_error_string().str);
319319

320-
THROW_ERROR_IF_NOT_EQUAL(
321-
rcl_action_publish_status(action_server, &status_message), RCL_RET_OK,
322-
rcl_get_error_string().str);
320+
rcl_ret_t ret = rcl_action_publish_status(action_server, &status_message);
321+
322+
std::string publish_error_msg;
323+
if (ret != RCL_RET_OK) {
324+
publish_error_msg = rcl_get_error_string().str;
325+
rcl_reset_error();
326+
}
327+
328+
rcl_ret_t ret_fini = rcl_action_goal_status_array_fini(&status_message);
329+
330+
if (ret != RCL_RET_OK) {
331+
Napi::Error::New(env, publish_error_msg).ThrowAsJavaScriptException();
332+
return env.Undefined();
333+
}
334+
335+
if (ret_fini != RCL_RET_OK) {
336+
Napi::Error::New(env, rcl_get_error_string().str)
337+
.ThrowAsJavaScriptException();
338+
rcl_reset_error();
339+
return env.Undefined();
340+
}
323341

324342
return env.Undefined();
325343
}

0 commit comments

Comments
 (0)