Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix _z_query_copy #496

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/zenoh-pico/net/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct _z_query_t {

_z_query_t _z_query_null(void);
void _z_query_clear(_z_query_t *q);
void _z_query_copy(_z_query_t *dst, const _z_query_t *src);
int8_t _z_query_copy(_z_query_t *dst, const _z_query_t *src);
void _z_query_free(_z_query_t **query);

_Z_REFCOUNT_DEFINE(_z_query, _z_query)
Expand Down
35 changes: 26 additions & 9 deletions src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ _z_query_t _z_query_null(void) {
._parameters = NULL,
._request_id = 0,
._value = _z_value_null(),
.attachment = _z_bytes_null(),
._zn = {.in = NULL},
};
}

void _z_query_clear_inner(_z_query_t *q) {
_z_keyexpr_clear(&q->_key);
_z_value_clear(&q->_value);
_z_bytes_drop(&q->attachment);
z_free(q->_parameters);
_z_session_weak_drop(&q->_zn);
}

void _z_query_clear(_z_query_t *q) {
// Try to upgrade session weak to rc
_z_session_rc_t sess_rc = _z_session_weak_upgrade(&q->_zn);
Expand All @@ -40,20 +49,28 @@ void _z_query_clear(_z_query_t *q) {
_z_session_rc_drop(&sess_rc);
}
// Clean up memory
z_free(q->_parameters);
_z_keyexpr_clear(&q->_key);
_z_value_clear(&q->_value);
_z_bytes_drop(&q->attachment);
_z_session_weak_drop(&q->_zn);
_z_query_clear_inner(q);
}

void _z_query_copy(_z_query_t *dst, const _z_query_t *src) {
int8_t _z_query_copy(_z_query_t *dst, const _z_query_t *src) {
*dst = _z_query_null();
_Z_RETURN_IF_ERR(_z_keyexpr_copy(&dst->_key, &src->_key));
_Z_CLEAN_RETURN_IF_ERR(_z_value_copy(&dst->_value, &src->_value), _z_query_clear_inner(dst));
_Z_CLEAN_RETURN_IF_ERR(_z_bytes_copy(&dst->attachment, &src->attachment), _z_query_clear_inner(dst));
dst->_parameters = _z_str_clone(src->_parameters);
if (dst->_parameters == NULL && src->_parameters != NULL) {
_z_query_clear_inner(dst);
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
_z_session_weak_copy(&dst->_zn, &src->_zn);
if (dst->_zn.in == NULL) {
_z_query_clear_inner(dst);
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
dst->_anyke = src->_anyke;
dst->_key = _z_keyexpr_duplicate(src->_key);
dst->_parameters = src->_parameters;
dst->_request_id = src->_request_id;
dst->_zn = src->_zn;
_z_value_copy(&dst->_value, &src->_value);
return _Z_RES_OK;
}

void _z_query_free(_z_query_t **query) {
Expand Down
2 changes: 1 addition & 1 deletion zenohpico.pc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ prefix=/usr/local
Name: zenohpico
Description:
URL:
Version: 1.0.20240711dev
Version: 1.0.20240715dev
Cflags: -I${prefix}/include
Libs: -L${prefix}/lib -lzenohpico
Loading