Skip to content

Commit

Permalink
Free resources in error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
filonenko-mikhail committed Dec 22, 2021
1 parent c52df71 commit 202fbbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kafka/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ rebalance_msg_t *new_rebalance_revoke_msg(rd_kafka_topic_partition_list_t *revok

pthread_mutex_t lock;
if (pthread_mutex_init(&lock, NULL) != 0) {
free(msg);
return NULL;
}

msg->lock = lock;

pthread_cond_t sync;
if (pthread_cond_init(&sync, NULL) != 0) {
free(msg);
return NULL;
}

Expand All @@ -181,13 +183,15 @@ rebalance_msg_t *new_rebalance_assign_msg(rd_kafka_topic_partition_list_t *assig

pthread_mutex_t lock;
if (pthread_mutex_init(&lock, NULL) != 0) {
free(msg);
return NULL;
}

msg->lock = lock;

pthread_cond_t sync;
if (pthread_cond_init(&sync, NULL) != 0) {
free(msg);
return NULL;
}

Expand All @@ -206,13 +210,15 @@ rebalance_msg_t *new_rebalance_error_msg(rd_kafka_resp_err_t err) {

pthread_mutex_t lock;
if (pthread_mutex_init(&lock, NULL) != 0) {
free(msg);
return NULL;
}

msg->lock = lock;

pthread_cond_t sync;
if (pthread_cond_init(&sync, NULL) != 0) {
free(msg);
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions kafka/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ new_queue() {

pthread_mutex_t lock;
if (pthread_mutex_init(&lock, NULL) != 0) {
free(queue);
return NULL;
}

Expand Down

0 comments on commit 202fbbe

Please sign in to comment.