Skip to content

Commit

Permalink
fix: properly clone the pointer of query and reply to resolve the seg…
Browse files Browse the repository at this point in the history
…fault in test_service__rmw_zenoh_cpp
  • Loading branch information
YuanYuYuan committed Sep 27, 2024
1 parent 6a48919 commit 6fd7e1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,21 +493,21 @@ void sub_data_handler(
}

///=============================================================================
ZenohQuery::ZenohQuery(z_owned_query_t * query)
ZenohQuery::ZenohQuery(z_owned_query_t query)
{
query_ = query;
}

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

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

//==============================================================================
Expand All @@ -530,25 +530,25 @@ void service_data_handler(z_loaned_query_t * query, void * data)
z_owned_query_t owned_query;
z_query_clone(&owned_query, query);

service_data->add_new_query(std::make_unique<ZenohQuery>(&owned_query));
service_data->add_new_query(std::make_unique<ZenohQuery>(owned_query));
}

///=============================================================================
ZenohReply::ZenohReply(z_owned_reply_t * reply)
ZenohReply::ZenohReply(z_owned_reply_t reply)
{
reply_ = reply;
}

///=============================================================================
ZenohReply::~ZenohReply()
{
z_drop(z_move(*reply_));
z_drop(z_move(reply_));
}

///=============================================================================
const z_loaned_reply_t * ZenohReply::get_reply() const
{
return z_loan(*reply_);
return z_loan(reply_);
}

///=============================================================================
Expand Down Expand Up @@ -579,7 +579,7 @@ void client_data_handler(z_loaned_reply_t * reply, void * data)
if (z_reply_is_ok(reply)) {
z_owned_reply_t owned_reply;
z_reply_clone(&owned_reply, reply);
client_data->add_new_reply(std::make_unique<ZenohReply>(&owned_reply));
client_data->add_new_reply(std::make_unique<ZenohReply>(owned_reply));
} else {
z_view_string_t keystr;
z_keyexpr_as_view_string(z_loan(client_data->keyexpr), &keystr);
Expand Down
8 changes: 4 additions & 4 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ void client_data_drop(void * data);
class ZenohQuery final
{
public:
ZenohQuery(z_owned_query_t * query);
ZenohQuery(z_owned_query_t query);

~ZenohQuery();

const z_loaned_query_t * get_query() const;

private:
z_owned_query_t * query_;
z_owned_query_t query_;
};

///=============================================================================
Expand Down Expand Up @@ -280,14 +280,14 @@ class rmw_service_data_t final
class ZenohReply final
{
public:
ZenohReply(z_owned_reply_t * reply);
ZenohReply(z_owned_reply_t reply);

~ZenohReply();

const z_loaned_reply_t * get_reply() const;

private:
z_owned_reply_t * reply_;
z_owned_reply_t reply_;
};

///=============================================================================
Expand Down

0 comments on commit 6fd7e1c

Please sign in to comment.