Skip to content

Commit 1a1586c

Browse files
Colin Deasyedenhill
authored andcommitted
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 aba76de commit 1a1586c

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy