closes bpo-41235: Fix the error handling in SSLContext.load_dh_params() (GH-21385)

diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 5e82fe4..5806417 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -4309,8 +4309,10 @@
         }
         return NULL;
     }
-    if (SSL_CTX_set_tmp_dh(self->ctx, dh) == 0)
-        _setSSLError(NULL, 0, __FILE__, __LINE__);
+    if (!SSL_CTX_set_tmp_dh(self->ctx, dh)) {
+        DH_free(dh);
+        return _setSSLError(NULL, 0, __FILE__, __LINE__);
+    }
     DH_free(dh);
     Py_RETURN_NONE;
 }