Skip to content

Commit

Permalink
fix: segmentation fault due to the unallocated query memory
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan committed Aug 19, 2024
1 parent bf0da8a commit dfc95ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
6 changes: 3 additions & 3 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ void sub_data_handler(const z_loaned_sample_t *sample, void *data) {

///=============================================================================
ZenohQuery::ZenohQuery(const z_loaned_query_t *query) {
z_query_clone(query_, query);
z_query_clone(&query_, query);
}

///=============================================================================
ZenohQuery::~ZenohQuery() { z_drop(z_move(*query_)); }
ZenohQuery::~ZenohQuery() { z_drop(z_move(query_)); }

///=============================================================================
const z_loaned_query_t *ZenohQuery::get_query() const {
return z_query_loan(query_);
return z_query_loan(&query_);
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ZenohQuery final
const z_loaned_query_t * get_query() const;

private:
z_owned_query_t * query_{nullptr};
z_owned_query_t query_;
};

///=============================================================================
Expand Down
2 changes: 0 additions & 2 deletions rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,6 @@ rmw_ret_t rmw_init(const rmw_init_options_t *options, rmw_context_t *context) {
free_shm_provider.cancel();
restore_context.cancel();



return RMW_RET_OK;
}

Expand Down
21 changes: 7 additions & 14 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,17 +1416,14 @@ rmw_subscription_t *rmw_create_subscription(
sub_options.reliability = Z_RELIABILITY_RELIABLE;
}

;

ze_owned_querying_subscriber_t *sub =
&std::get<ze_owned_querying_subscriber_t>(sub_data->sub);
ze_declare_querying_subscriber(sub, z_loan(context_impl->session),
ze_owned_querying_subscriber_t sub;
if (ze_declare_querying_subscriber(&sub, z_loan(context_impl->session),
z_loan(keyexpr), z_move(callback),
&sub_options);
if (!z_check(*sub)) {
&sub_options)) {
RMW_SET_ERROR_MSG("unable to create zenoh subscription");
return nullptr;
}
sub_data->sub = sub;
} else {
// Create a regular subscriber for all other durability settings.
z_subscriber_options_t sub_options;
Expand All @@ -1435,13 +1432,12 @@ rmw_subscription_t *rmw_create_subscription(
sub_options.reliability = Z_RELIABILITY_RELIABLE;
}

z_owned_subscriber_t *sub = &std::get<z_owned_subscriber_t>(sub_data->sub);
z_declare_subscriber(sub, z_loan(context_impl->session), z_loan(keyexpr),
z_move(callback), &sub_options);
if (!z_check(*sub)) {
z_owned_subscriber_t sub;
if(z_declare_subscriber(&sub, z_loan(context_impl->session), z_loan(keyexpr), z_move(callback), &sub_options)) {
RMW_SET_ERROR_MSG("unable to create zenoh subscription");
return nullptr;
}
sub_data->sub = sub;
}

auto undeclare_z_sub = rcpputils::make_scope_exit([sub_data]() {
Expand Down Expand Up @@ -2374,9 +2370,6 @@ rmw_ret_t rmw_send_request(const rmw_client_t *client, const void *ros_request,

z_owned_closure_reply_t callback;
z_closure(&callback, rmw_zenoh_cpp::client_data_handler, NULL, client_data);

// TODO(yuyuan): z_owned_closure_reply_t zn_closure_reply is replaced with a
// moved callback
z_get(z_loan(context_impl->session), z_loan(client_data->keyexpr), "",
z_move(callback), &opts);

Expand Down

0 comments on commit dfc95ad

Please sign in to comment.