Skip to content

Commit eb7fd2a

Browse files
committed
Merge pull request #2989 from jkseppan/tidyup-ttconv
Don't call Py_DECREF on null in _ttconv.cpp
2 parents 03e60dc + 3dd16b5 commit eb7fd2a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/_ttconv.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Python.h>
1212
#include "ttconv/pprdrv.h"
1313
#include <vector>
14+
#include <cassert>
1415

1516
class PythonExceptionOccurred
1617
{
@@ -185,14 +186,17 @@ class PythonDictionaryCallback : public TTDictionaryCallback
185186

186187
virtual void add_pair(const char* a, const char* b)
187188
{
189+
assert(a != NULL);
190+
assert(b != NULL);
188191
PyObject* value = PyBytes_FromString(b);
189-
if (value)
192+
if (!value)
190193
{
191-
if (PyDict_SetItemString(_dict, a, value))
192-
{
193-
Py_DECREF(value);
194-
throw PythonExceptionOccurred();
195-
}
194+
throw PythonExceptionOccurred();
195+
}
196+
if (PyDict_SetItemString(_dict, a, value))
197+
{
198+
Py_DECREF(value);
199+
throw PythonExceptionOccurred();
196200
}
197201
Py_DECREF(value);
198202
}

0 commit comments

Comments
 (0)