diff --git a/src/collections/bytes.c b/src/collections/bytes.c index aa81f07f0..5f8ab571c 100644 --- a/src/collections/bytes.c +++ b/src/collections/bytes.c @@ -33,7 +33,7 @@ z_result_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src) { _z_bytes_t _z_bytes_alias(const _z_bytes_t src) { _z_bytes_t dst; - dst._slices = _z_arc_slice_svec_alias(&src._slices); + dst._slices = src._slices; return dst; } diff --git a/src/net/encoding.c b/src/net/encoding.c index 5349d3155..49d2e4794 100644 --- a/src/net/encoding.c +++ b/src/net/encoding.c @@ -59,7 +59,7 @@ _z_encoding_t _z_encoding_alias(_z_encoding_t src) { _z_encoding_t dst; dst.id = src.id; if (_z_string_check(&src.schema)) { - _z_string_alias(src.schema); + dst.schema = _z_string_alias(src.schema); } else { dst.schema = _z_string_null(); } diff --git a/src/net/query.c b/src/net/query.c index 219e04d12..817e94a59 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -29,7 +29,7 @@ static void _z_query_clear_inner(_z_query_t *q) { z_result_t _z_query_send_reply_final(_z_query_t *q) { // Try to upgrade session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade_if_open(&q->_zn); - if (!_Z_RC_IS_NULL(&sess_rc)) { + if (_Z_RC_IS_NULL(&sess_rc)) { return _Z_ERR_TRANSPORT_TX_FAILED; } _z_zenoh_message_t z_msg = _z_n_msg_make_response_final(q->_request_id); diff --git a/src/session/queryable.c b/src/session/queryable.c index 8c9e56895..cc1ef0b82 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -200,7 +200,16 @@ static z_result_t _z_session_queryable_get_infos(_z_session_t *zn, const _z_keye return _Z_RES_OK; } -static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, const _z_keyexpr_t *q_key, +static inline void _z_queryable_query_steal_data(_z_query_t *query, _z_session_rc_t *zsrc, _z_msg_query_t *msgq, + _z_keyexpr_t *key, uint32_t qid, bool anyke) { + // Steal received data in query + *query = _z_query_alias(&msgq->_ext_value, key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke); + msgq->_ext_value = _z_value_null(); + msgq->_ext_attachment = _z_bytes_null(); + msgq->_parameters = _z_slice_null(); +} + +static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z_keyexpr_t *q_key, uint32_t qid) { _z_session_t *zn = _Z_RC_IN_VAL(zsrc); _z_keyexpr_t key; @@ -224,9 +233,15 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer } } // Build the z_query - _z_query_t q = - _z_query_alias(&msgq->_ext_value, &key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke); - _z_query_rc_t query = _z_query_rc_new_from_val(&q); + _z_query_t *q = z_malloc(sizeof(_z_query_t)); + if (q == NULL) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + _z_query_rc_t query = _z_query_rc_new(q); + if (_Z_RC_IS_NULL(&query)) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + _z_queryable_query_steal_data(q, zsrc, msgq, &key, qid, anyke); // Parse session_queryable svec for (size_t i = 0; i < qle_nb; i++) { _z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qles, i); @@ -245,8 +260,7 @@ z_result_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z z_result_t ret = _z_trigger_queryables_inner(zsrc, msgq, q_key, qid); // Clean up _z_keyexpr_clear(q_key); - _z_encoding_clear(&msgq->_ext_value.encoding); - _z_bytes_drop(&msgq->_ext_value.payload); + _z_value_clear(&msgq->_ext_value); _z_bytes_drop(&msgq->_ext_attachment); _z_slice_clear(&msgq->_parameters); return ret;