Skip to content

Commit

Permalink
Free cluster_async_data when hiredis can't push the callback
Browse files Browse the repository at this point in the history
When hiredis API `redisAsyncFormattedCommand()` fail to push a given callback to its
internal queue we need to free the cluster_async_data (used as privdata).
  • Loading branch information
bjosv committed Aug 17, 2024
1 parent 1efe528 commit 0a57552
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hircluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -4138,7 +4138,7 @@ int redisClusterAsyncFormattedCommand(redisClusterAsyncContext *acc,
redisAsyncContext *ac;
struct cmd *command = NULL;
hilist *commands = NULL;
cluster_async_data *cad;
cluster_async_data *cad = NULL;

if (acc == NULL) {
return REDIS_ERR;
Expand Down Expand Up @@ -4225,6 +4225,7 @@ int redisClusterAsyncFormattedCommand(redisClusterAsyncContext *acc,

cad->acc = acc;
cad->command = command;
command = NULL; /* Memory ownership moved. */
cad->callback = fn;
cad->privdata = privdata;

Expand All @@ -4245,6 +4246,7 @@ int redisClusterAsyncFormattedCommand(redisClusterAsyncContext *acc,
// passthrough

error:
cluster_async_data_free(cad);
command_destroy(command);
if (commands != NULL) {
listRelease(commands);
Expand Down Expand Up @@ -4303,6 +4305,7 @@ int redisClusterAsyncFormattedCommandToNode(redisClusterAsyncContext *acc,

cad->acc = acc;
cad->command = command;
command = NULL; /* Memory ownership moved. */
cad->callback = fn;
cad->privdata = privdata;
cad->retry_count = NO_RETRY;
Expand All @@ -4319,6 +4322,7 @@ int redisClusterAsyncFormattedCommandToNode(redisClusterAsyncContext *acc,
// passthrough

error:
cluster_async_data_free(cad);
command_destroy(command);
return REDIS_ERR;
}
Expand Down

0 comments on commit 0a57552

Please sign in to comment.