]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_testmultiphase: Fix possible ref leak (GH-22881)
authorDong-hee Na <donghee.na92@gmail.com>
Thu, 22 Oct 2020 09:44:18 +0000 (18:44 +0900)
committerGitHub <noreply@github.com>
Thu, 22 Oct 2020 09:44:18 +0000 (02:44 -0700)
This is just test code, but sometimes external contributors reference the code snippets from test code.
`PyModule_AddObject` should be handled in the proper way.

https://docs.python.org/3/c-api/module.html#c.PyModule_AddObject

Modules/_testmultiphase.c

index d69ae628fa7a40d3fc82a7baa3d25a5641a78fc3..8bba077be9bb6882e50c465160eb7c6e144ccf83 100644 (file)
@@ -359,6 +359,7 @@ static int execfunc(PyObject *m)
         goto fail;
     }
     if (PyModule_AddObject(m, "Example", temp) != 0) {
+        Py_DECREF(temp);
         goto fail;
     }
 
@@ -369,6 +370,7 @@ static int execfunc(PyObject *m)
         goto fail;
     }
     if (PyModule_AddObject(m, "error", temp) != 0) {
+        Py_DECREF(temp);
         goto fail;
     }
 
@@ -378,6 +380,7 @@ static int execfunc(PyObject *m)
         goto fail;
     }
     if (PyModule_AddObject(m, "Str", temp) != 0) {
+        Py_DECREF(temp);
         goto fail;
     }
 
@@ -807,6 +810,7 @@ meth_state_access_exec(PyObject *m)
         return -1;
     }
     if (PyModule_AddObject(m, "StateAccessType", temp) != 0) {
+        Py_DECREF(temp);
         return -1;
     }