From 01fbc129a5749e3d3f6f3082e7ed7154015a0527 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 3 Dec 2024 15:02:35 +0100 Subject: [PATCH] fix: queryables issues --- src/collections/bytes.c | 2 +- src/net/encoding.c | 2 +- src/net/query.c | 2 +- src/session/queryable.c | 10 +++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) 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..7b024b3e9 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -200,7 +200,7 @@ 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 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; @@ -227,6 +227,14 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer _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); + if (_Z_RC_IS_NULL(&query)) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + // Clear values to avoid double free + *q_key = _z_keyexpr_null(); + msgq->_ext_value = _z_value_null(); + msgq->_ext_attachment = _z_bytes_null(); + msgq->_parameters = _z_slice_null(); // 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);