Skip to content

Commit

Permalink
fix: query/reply memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jun 14, 2024
1 parent 4f4b952 commit ef610ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co
_z_bytes_from_owned_bytes(opt.attachment));
// Clean-up
z_encoding_drop(opt.encoding);
z_bytes_drop(opt.attachment);
return ret;
}

Expand Down Expand Up @@ -1139,6 +1140,7 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co
}
// Clean-up
z_encoding_drop(opt.encoding);
z_bytes_drop(opt.attachment);
return ret;
}

Expand Down Expand Up @@ -1227,6 +1229,7 @@ int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *ke
}
// Clean-up
z_encoding_drop(opts.encoding);
z_bytes_drop(opts.attachment);
return ret;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _z_query_t _z_query_create(const _z_value_t *value, const _z_keyexpr_t *key, con
memcpy(q._parameters, parameters->start, parameters->len);
q._parameters[parameters->len] = 0;
q._anyke = (strstr(q._parameters, Z_SELECTOR_QUERY_MATCH) == NULL) ? false : true;
q.attachment = att;
q.attachment._slice = _z_slice_steal((_z_slice_t *)&att._slice);

_z_keyexpr_copy(&q._key, key);
_z_value_copy(&q._value, value);
Expand Down
2 changes: 1 addition & 1 deletion src/net/reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ _z_reply_t _z_reply_create(_z_keyexpr_t keyexpr, z_reply_tag_t tag, _z_id_t id,
_z_slice_copy(&sample.payload._slice, payload);
sample.kind = kind;
sample.timestamp = _z_timestamp_duplicate(timestamp);
sample.attachment = _z_bytes_duplicate(&att);
sample.attachment._slice = _z_slice_steal((_z_slice_t *)&att._slice);

// Create sample rc from value
reply.data.sample = _z_sample_rc_new_from_val(sample);
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/codec/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ int8_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
ret = _z_source_info_decode(&pshb->_body._put._commons._source_info, &zbf);
break;
}
case _Z_MSG_EXT_ENC_ZBUF | 0x03: {
case _Z_MSG_EXT_ENC_ZBUF | 0x03: { // Attachment
pshb->_body._put._attachment._slice = extension->_body._zbuf._val._is_alloc
? _z_slice_steal(&extension->_body._zbuf._val)
: _z_slice_duplicate(&extension->_body._zbuf._val);
Expand Down Expand Up @@ -448,7 +448,7 @@ int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
_z_slice_copy(&msg->_ext_value.payload._slice, &bytes);
break;
}
case _Z_MSG_EXT_ENC_ZBUF | 0x05: {
case _Z_MSG_EXT_ENC_ZBUF | 0x05: { // Attachment
msg->_ext_attachment._slice = extension->_body._zbuf._val._is_alloc
? _z_slice_steal(&extension->_body._zbuf._val)
: _z_slice_duplicate(&extension->_body._zbuf._val);
Expand Down

0 comments on commit ef610ea

Please sign in to comment.