Skip to content

Commit 8f6ceec

Browse files
author
Colin Deasy
committed
Safe release handler resources
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.
1 parent 3442602 commit 8f6ceec

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

confluent_kafka/src/confluent_kafka.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,16 +1324,25 @@ static void log_cb (const rd_kafka_t *rk, int level,
13241324
* Clear Python object references in Handle
13251325
*/
13261326
void Handle_clear (Handle *h) {
1327-
if (h->error_cb)
1328-
Py_DECREF(h->error_cb);
1327+
if (h->error_cb) {
1328+
Py_DECREF(h->error_cb);
1329+
h->error_cb = NULL;
1330+
}
13291331

1330-
if (h->throttle_cb)
1332+
if (h->throttle_cb) {
13311333
Py_DECREF(h->throttle_cb);
1334+
h->throttle_cb = NULL;
1335+
}
13321336

1333-
if (h->stats_cb)
1334-
Py_DECREF(h->stats_cb);
1337+
if (h->stats_cb) {
1338+
Py_DECREF(h->stats_cb);
1339+
h->stats_cb = NULL;
1340+
}
13351341

1336-
Py_XDECREF(h->logger);
1342+
if (h->logger) {
1343+
Py_DECREF(h->logger);
1344+
h->logger = NULL;
1345+
}
13371346

13381347
if (h->initiated) {
13391348
#ifdef WITH_PY_TSS

0 commit comments

Comments
 (0)