Skip to content

Commit

Permalink
Check ptr in dictRelease
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
  • Loading branch information
bjosv committed Oct 9, 2024
1 parent 432f689 commit 972b25f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
6 changes: 2 additions & 4 deletions src/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ static valkeyAsyncContext *valkeyAsyncInitialize(valkeyContext *c) {

return ac;
oom:
if (channels)
dictRelease(channels);
if (patterns)
dictRelease(patterns);
dictRelease(channels);
dictRelease(patterns);
return NULL;
}

Expand Down
26 changes: 7 additions & 19 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,7 @@ static dict *parse_cluster_slots(valkeyClusterContext *cc, valkeyReply *reply) {
// passthrough

error:
if (nodes != NULL) {
dictRelease(nodes);
}
dictRelease(nodes);
if (slot != NULL) {
cluster_slot_destroy(slot);
}
Expand Down Expand Up @@ -1037,9 +1035,7 @@ static dict *parse_cluster_nodes(valkeyClusterContext *cc, valkeyReply *reply) {
goto error;
}

if (nodes_name != NULL) {
dictRelease(nodes_name);
}
dictRelease(nodes_name);

return nodes;

Expand All @@ -1050,12 +1046,8 @@ static dict *parse_cluster_nodes(valkeyClusterContext *cc, valkeyReply *reply) {
error:
sdsfreesplitres(part, count_part);
sdsfreesplitres(slot_start_end, count_slot_start_end);
if (nodes != NULL) {
dictRelease(nodes);
}
if (nodes_name != NULL) {
dictRelease(nodes_name);
}
dictRelease(nodes);
dictRelease(nodes_name);
return NULL;
}

Expand Down Expand Up @@ -1233,9 +1225,8 @@ static int updateNodesAndSlotmap(valkeyClusterContext *cc, dict *nodes) {
* the release procedure might access cc->nodes. */
dict *oldnodes = cc->nodes;
cc->nodes = nodes;
if (oldnodes != NULL) {
dictRelease(oldnodes);
}
dictRelease(oldnodes);

if (cc->event_callback != NULL) {
cc->event_callback(cc, VALKEYCLUSTER_EVENT_SLOTMAP_UPDATED,
cc->event_privdata);
Expand Down Expand Up @@ -1322,10 +1313,7 @@ void valkeyClusterFree(valkeyClusterContext *cc) {
vk_free(cc->username);
vk_free(cc->password);
vk_free(cc->table);

if (cc->nodes != NULL) {
dictRelease(cc->nodes);
}
dictRelease(cc->nodes);

if (cc->requests != NULL) {
listRelease(cc->requests);
Expand Down
2 changes: 2 additions & 0 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ static int _dictClear(dict *ht) {

/* Clear & Release the hash table */
void dictRelease(dict *ht) {
if (ht == NULL)
return;
_dictClear(ht);
vk_free(ht);
}
Expand Down

0 comments on commit 972b25f

Please sign in to comment.