Skip to content

Commit 740c40b

Browse files
committed
Don't leak when PyDict_SetItemString called
1 parent b685765 commit 740c40b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

softioc/extension.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020

2121
/* Helper for function below. */
2222
#define ADD_ENUM(dict, name) \
23-
PyDict_SetItemString(dict, #name, PyInt_FromLong(name))
23+
tmp = PyInt_FromLong(name); \
24+
PyDict_SetItemString(dict, #name, tmp); \
25+
Py_XDECREF(tmp);
2426

2527
/* Alas, EPICS has changed the numerical assignments of the DBF_ enums between
2628
* versions, so to avoid unpleasant surprises, we compute thes values here in C
2729
* and pass them back to the Python layer. */
2830
static PyObject *get_DBF_values(PyObject *self, PyObject *args)
2931
{
3032
PyObject *dict = PyDict_New();
33+
PyObject *tmp;
3134
ADD_ENUM(dict, DBF_STRING);
3235
ADD_ENUM(dict, DBF_CHAR);
3336
ADD_ENUM(dict, DBF_UCHAR);
@@ -77,6 +80,7 @@ static PyObject *get_field_offsets(PyObject *self, PyObject *args)
7780
dbentry.pflddes->size,
7881
dbentry.pflddes->field_type);
7982
PyDict_SetItemString(dict, field_name, ost);
83+
Py_XDECREF(ost);
8084
status = dbNextField(&dbentry, 0);
8185
}
8286

0 commit comments

Comments
 (0)