Skip to content

Commit

Permalink
Fix queryables memory leak (#880)
Browse files Browse the repository at this point in the history
* fix: null malloc allocation

* fix: memory leak in queryables

* fix: avoid api call null size alloc

* fix: cmake unstable warning

* build: bad compile config in workflow

* fix: revert matching changes
  • Loading branch information
jean-roland authored Feb 3, 2025
1 parent 863b7e9 commit 07700e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 07700e4

Please sign in to comment.