From b3d782374069d18551d2947008210ab8c53ff072 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 12 Mar 2023 00:11:48 +1100 Subject: [PATCH] Decrement reference count --- src/_imaging.c | 1 + src/_imagingft.c | 12 ++++++++++++ src/_imagingmorph.c | 5 +++++ src/_imagingtk.c | 6 +++++- src/_webp.c | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/_imaging.c b/src/_imaging.c index dc14361f626..3cc94328622 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -4306,6 +4306,7 @@ PyInit__imaging(void) { m = PyModule_Create(&module_def); if (setup_module(m) < 0) { + Py_DECREF(m); return NULL; } diff --git a/src/_imagingft.c b/src/_imagingft.c index 3e5244b2f03..93866ec4da0 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -1090,6 +1090,7 @@ font_getvarnames(FontObject *self) { for (i = 0; i < name_count; i++) { error = FT_Get_Sfnt_Name(self->face, i, &name); if (error) { + Py_DECREF(list_names); return geterror(error); } @@ -1136,6 +1137,11 @@ font_getvaraxes(FontObject *self) { list_axis = PyDict_New(); if (list_axis == NULL) { + for (j = 0; j < i; j++) { + list_axis = PyList_GetItem(list_axes, j); + Py_DECREF(list_axis); + } + Py_DECREF(list_axes); return NULL; } PyDict_SetItemString( @@ -1147,6 +1153,12 @@ font_getvaraxes(FontObject *self) { for (j = 0; j < name_count; j++) { error = FT_Get_Sfnt_Name(self->face, j, &name); if (error) { + Py_DECREF(list_axis); + for (j = 0; j < i; j++) { + list_axis = PyList_GetItem(list_axes, j); + Py_DECREF(list_axis); + } + Py_DECREF(list_axes); return geterror(error); } diff --git a/src/_imagingmorph.c b/src/_imagingmorph.c index 43b72539df0..3e0c9172a0a 100644 --- a/src/_imagingmorph.c +++ b/src/_imagingmorph.c @@ -141,11 +141,13 @@ match(PyObject *self, PyObject *args) { } if (!PyArg_ParseTuple(args, "On", &py_lut, &i0)) { + Py_DECREF(ret); PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem"); return NULL; } if (!PyBytes_Check(py_lut)) { + Py_DECREF(ret); PyErr_SetString(PyExc_RuntimeError, "The morphology LUT is not a bytes object"); return NULL; } @@ -153,6 +155,7 @@ match(PyObject *self, PyObject *args) { lut_len = PyBytes_Size(py_lut); if (lut_len < LUT_SIZE) { + Py_DECREF(ret); PyErr_SetString(PyExc_RuntimeError, "The morphology LUT has the wrong size"); return NULL; } @@ -161,6 +164,7 @@ match(PyObject *self, PyObject *args) { imgin = (Imaging)i0; if (imgin->type != IMAGING_TYPE_UINT8 || imgin->bands != 1) { + Py_DECREF(ret); PyErr_SetString(PyExc_RuntimeError, "Unsupported image type"); return NULL; } @@ -221,6 +225,7 @@ get_on_pixels(PyObject *self, PyObject *args) { } if (!PyArg_ParseTuple(args, "n", &i0)) { + Py_DECREF(ret); PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem"); return NULL; } diff --git a/src/_imagingtk.c b/src/_imagingtk.c index b9273b0b882..ac6a2313872 100644 --- a/src/_imagingtk.c +++ b/src/_imagingtk.c @@ -58,5 +58,9 @@ PyInit__imagingtk(void) { }; PyObject *m; m = PyModule_Create(&module_def); - return (load_tkinter_funcs() == 0) ? m : NULL; + if (load_tkinter_funcs() != 0) { + Py_DECREF(m); + return NULL;; + } + return m; } diff --git a/src/_webp.c b/src/_webp.c index 493e0709c46..0e38453cb7f 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -987,6 +987,7 @@ PyInit__webp(void) { m = PyModule_Create(&module_def); if (setup_module(m) < 0) { + Py_DECREF(m); return NULL; }