From 1c61629e921c0ff5215549c03bbec7a801e64d42 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 14 Dec 2024 15:46:36 +1100 Subject: [PATCH] Decrement reference count --- src/_avif.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/_avif.c b/src/_avif.c index ae421e1b92c..45f014f86a4 100644 --- a/src/_avif.c +++ b/src/_avif.c @@ -1006,18 +1006,15 @@ static PyMethodDef avifMethods[] = { static int setup_module(PyObject *m) { - PyObject *d = PyModule_GetDict(m); - - PyObject *v = PyUnicode_FromString(avifVersion()); - if (PyDict_SetItemString(d, "libavif_version", v) < 0) { - Py_DECREF(v); - return -1; - } - Py_DECREF(v); - if (PyType_Ready(&AvifDecoder_Type) < 0 || PyType_Ready(&AvifEncoder_Type) < 0) { return -1; } + + PyObject *d = PyModule_GetDict(m); + PyObject *v = PyUnicode_FromString(avifVersion()); + PyDict_SetItemString(d, "libavif_version", v ? v : Py_None); + Py_XDECREF(v); + return 0; } @@ -1034,6 +1031,7 @@ PyInit__avif(void) { m = PyModule_Create(&module_def); if (setup_module(m) < 0) { + Py_DECREF(m); return NULL; }