Skip to content

Commit

Permalink
Setup/cleanup (struct msg)->msg_info correctly
Browse files Browse the repository at this point in the history
Without proper cleanup, we risk leaking memory and having multiple
owners overwriting the same memory.
  • Loading branch information
smukil committed Nov 3, 2019
1 parent b394564 commit 7d76e25
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/dyn_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ static struct msg *_msg_get(struct conn *conn, bool request,
msg->additional_each_rspmgrs = NULL;
msg->rspmgrs_inited = false;

// Init the write_with_ts struct:
struct write_with_ts *minfo = &msg->msg_info;
minfo->add_set = NULL;
minfo->rem_set = NULL;
minfo->keys = NULL;
minfo->num_keys = 0;
minfo->fields = NULL;
minfo->num_fields = 0;
minfo->values = NULL;
minfo->num_values = 0;
minfo->optionals = NULL;
minfo->num_optionals = 0;
minfo->rewrite_script = NULL;
minfo->total_num_tokens = 0;
return msg;
}

Expand Down Expand Up @@ -647,6 +661,19 @@ void msg_put(struct msg *msg) {
msg->orig_msg = NULL;
}

if (msg->msg_info.keys) {
array_destroy(msg->msg_info.keys);
}
if (msg->msg_info.fields) {
array_destroy(msg->msg_info.fields);
}
if (msg->msg_info.values) {
array_destroy(msg->msg_info.values);
}
if (msg->msg_info.optionals) {
array_destroy(msg->msg_info.optionals);
}

if (msg->additional_each_rspmgrs) {
ASSERT(msg->consistency == DC_EACH_SAFE_QUORUM);
// Only requests have their connection's owner as the 'struct server_pool' object,
Expand Down

0 comments on commit 7d76e25

Please sign in to comment.