| 1 |
From: Colin Watson <[email protected]> |
| 2 |
Date: Fri, 5 Dec 2025 11:03:48 +0000 |
| 3 |
Subject: Don't leave NewTopic partially-initialized on error |
| 4 |
|
| 5 |
If `NewTopic` was initialized with a non-dict `config`, then the |
| 6 |
constructor raised an exception but left the object in a |
| 7 |
partially-initialized state with `replica_assignment` and `config` |
| 8 |
elements that hadn't had their reference counts increased, leading to |
| 9 |
mysterious segfaults in the test suite. Be more careful to only set |
| 10 |
these elements once we're ready to do so. |
| 11 |
|
| 12 |
Fixes: #2146 |
| 13 |
|
| 14 |
Forwarded: https://github.com/confluentinc/confluent-kafka-python/pull/2151 |
| 15 |
Bug: https://github.com/confluentinc/confluent-kafka-python/issues/2146 |
| 16 |
Bug-Debian: https://bugs.debian.org/1117901 |
| 17 |
Last-Update: 2025-12-05 |
| 18 |
--- |
| 19 |
src/confluent_kafka/src/AdminTypes.c | 15 +++++++++------ |
| 20 |
1 file changed, 9 insertions(+), 6 deletions(-) |
| 21 |
|
| 22 |
diff --git a/src/confluent_kafka/src/AdminTypes.c b/src/confluent_kafka/src/AdminTypes.c |
| 23 |
index 61adeb2..5baa17d 100644 |
| 24 |
--- a/src/confluent_kafka/src/AdminTypes.c |
| 25 |
+++ b/src/confluent_kafka/src/AdminTypes.c |
| 26 |
@@ -67,6 +67,7 @@ static int NewTopic_init (PyObject *self0, PyObject *args, |
| 27 |
PyObject *kwargs) { |
| 28 |
NewTopic *self = (NewTopic *)self0; |
| 29 |
const char *topic; |
| 30 |
+ PyObject *replica_assignment = NULL, *config = NULL; |
| 31 |
static char *kws[] = { "topic", |
| 32 |
"num_partitions", |
| 33 |
"replication_factor", |
| 34 |
@@ -82,22 +83,24 @@ static int NewTopic_init (PyObject *self0, PyObject *args, |
| 35 |
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiOO", kws, |
| 36 |
&topic, &self->num_partitions, |
| 37 |
&self->replication_factor, |
| 38 |
- &self->replica_assignment, |
| 39 |
- &self->config)) |
| 40 |
+ &replica_assignment, |
| 41 |
+ &config)) |
| 42 |
return -1; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
- if (self->config) { |
| 47 |
- if (!PyDict_Check(self->config)) { |
| 48 |
+ if (config) { |
| 49 |
+ if (!PyDict_Check(config)) { |
| 50 |
PyErr_SetString(PyExc_TypeError, |
| 51 |
"config must be a dict of strings"); |
| 52 |
return -1; |
| 53 |
} |
| 54 |
- Py_INCREF(self->config); |
| 55 |
+ Py_INCREF(config); |
| 56 |
+ self->config = config; |
| 57 |
} |
| 58 |
|
| 59 |
- Py_XINCREF(self->replica_assignment); |
| 60 |
+ Py_XINCREF(replica_assignment); |
| 61 |
+ self->replica_assignment = replica_assignment; |
| 62 |
|
| 63 |
self->topic = strdup(topic); |
| 64 |
|