]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40645: Fix ref leaks in _hashopenssl (GH-26079)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Wed, 12 May 2021 18:20:41 +0000 (20:20 +0200)
committerGitHub <noreply@github.com>
Wed, 12 May 2021 18:20:41 +0000 (19:20 +0100)
Modules/_hashopenssl.c

index 13634a579f0ddb8a3e20cc31c2d4f5903c42b95d..e4a28853775672f8b1da0f1c182b7177ce5af6bb 100644 (file)
@@ -2093,23 +2093,27 @@ hashlib_init_constructors(PyObject *module)
         }
         func  = PyObject_GetAttrString(module, fdef->ml_name);
         if (func == NULL) {
+            Py_DECREF(name_obj);
             return -1;
         }
-        if (PyDict_SetItem(state->constructs, func, name_obj) < 0) {
-            return -1;
-        }
+        int rc = PyDict_SetItem(state->constructs, func, name_obj);
         Py_DECREF(func);
         Py_DECREF(name_obj);
+        if (rc < 0) {
+            return -1;
+        }
     }
 
     proxy = PyDictProxy_New(state->constructs);
     if (proxy == NULL) {
         return -1;
     }
-    if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
+
+    int rc = PyModule_AddObjectRef(module, "_constructors", proxy);
+    Py_DECREF(proxy);
+    if (rc < 0) {
         return -1;
     }
-    Py_DECREF(proxy);
     return 0;
 }