Minor code cleanup in o_names_init
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 8 Dec 2021 13:14:48 +0000 (14:14 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 9 Dec 2021 18:25:29 +0000 (19:25 +0100)
This might result in a small memory leak.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17238)

(cherry picked from commit c50bf14450f3cd242f2211ca7e500191053d8050)

crypto/objects/o_names.c

index 05aa8c44aad4e7e63d682cb0d273c81d7ce0e6f5..92152eeb6674628c3a4838b5ef77d8e02503d876 100644 (file)
@@ -66,8 +66,14 @@ static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b);
 static CRYPTO_ONCE init = CRYPTO_ONCE_STATIC_INIT;
 DEFINE_RUN_ONCE_STATIC(o_names_init)
 {
-    names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp);
+    names_lh = NULL;
     obj_lock = CRYPTO_THREAD_lock_new();
+    if (obj_lock != NULL)
+        names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp);
+    if (names_lh == NULL) {
+        CRYPTO_THREAD_lock_free(obj_lock);
+        obj_lock = NULL;
+    }
     return names_lh != NULL && obj_lock != NULL;
 }