Skip to content

Commit

Permalink
Safe release handler resources
Browse files Browse the repository at this point in the history
During garbage collection tp_clear and tp_dealloc can both be called
which resulted in a double release of references.
This change safely decrements the reference count and invalidates the pointers.
  • Loading branch information
Colin Deasy authored and edenhill committed Aug 13, 2018
1 parent aba76de commit 1a1586c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions confluent_kafka/src/confluent_kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,16 +1324,25 @@ static void log_cb (const rd_kafka_t *rk, int level,
* Clear Python object references in Handle
*/
void Handle_clear (Handle *h) {
if (h->error_cb)
Py_DECREF(h->error_cb);
if (h->error_cb) {
Py_DECREF(h->error_cb);
h->error_cb = NULL;
}

if (h->throttle_cb)
if (h->throttle_cb) {
Py_DECREF(h->throttle_cb);
h->throttle_cb = NULL;
}

if (h->stats_cb)
Py_DECREF(h->stats_cb);
if (h->stats_cb) {
Py_DECREF(h->stats_cb);
h->stats_cb = NULL;
}

Py_XDECREF(h->logger);
if (h->logger) {
Py_DECREF(h->logger);
h->logger = NULL;
}

if (h->initiated) {
#ifdef WITH_PY_TSS
Expand Down

0 comments on commit 1a1586c

Please sign in to comment.