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 queryables memory leak #880

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ set(Z_FEATURE_TCP_NODELAY 1 CACHE STRING "Toggle TCP_NODELAY")
set(Z_FEATURE_LOCAL_SUBSCRIBER 0 CACHE STRING "Toggle local subscriptions")
set(Z_FEATURE_SESSION_CHECK 1 CACHE STRING "Toggle publisher/querier session check")
set(Z_FEATURE_BATCHING 1 CACHE STRING "Toggle batching")
set(Z_FEATURE_MATCHING 1 CACHE STRING "Toggle matching feature")
set(Z_FEATURE_MATCHING 0 CACHE STRING "Toggle matching feature")
jean-roland marked this conversation as resolved.
Show resolved Hide resolved
set(Z_FEATURE_RX_CACHE 0 CACHE STRING "Toggle RX_CACHE")
set(Z_FEATURE_AUTO_RECONNECT 1 CACHE STRING "Toggle automatic reconnection")

Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define Z_FEATURE_LOCAL_SUBSCRIBER 0
#define Z_FEATURE_PUBLISHER_SESSION_CHECK 1
#define Z_FEATURE_BATCHING 1
#define Z_FEATURE_MATCHING 1
#define Z_FEATURE_MATCHING 0
jean-roland marked this conversation as resolved.
Show resolved Hide resolved
#define Z_FEATURE_RX_CACHE 0
#define Z_FEATURE_AUTO_RECONNECT 1
// End of CMake generation
Expand Down
3 changes: 3 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ z_result_t z_bytes_to_string(const z_loaned_bytes_t *bytes, z_owned_string_t *s)
z_internal_string_null(s);
// Convert bytes to string
size_t len = _z_bytes_len(bytes);
if (len == 0) {
return _Z_RES_OK;
}
s->_val = _z_string_preallocate(len);
if (_z_string_len(&s->_val) != len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
_z_bytes_to_buf(bytes, (uint8_t *)_z_string_data(&s->_val), len);
Expand Down
5 changes: 4 additions & 1 deletion src/session/queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer
(int)_z_string_len(&qle_infos.ke_out._suffix), _z_string_data(&qle_infos.ke_out._suffix));
if (qle_infos.qle_nb == 0) {
_z_keyexpr_clear(&qle_infos.ke_out);
#if Z_FEATURE_RX_CACHE == 0
_z_queryable_infos_svec_release(&qle_infos.infos); // Otherwise it's released with cache
#endif
return _Z_RES_OK;
}
// Check anyke
Expand Down Expand Up @@ -243,7 +246,7 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer
_z_query_rc_drop(&query);
// Clean up
_z_keyexpr_clear(&qle_infos.ke_out);
#if Z_FEATURE_RX_CACHE != 1
#if Z_FEATURE_RX_CACHE == 0
_z_queryable_infos_svec_release(&qle_infos.infos); // Otherwise it's released with cache
#endif
return _Z_RES_OK;
Expand Down
Loading