GH773: Possible leak on CRYPTO_THREAD_lock_new failure
authorFdaSilvaYY <fdasilvayy@gmail.com>
Tue, 1 Mar 2016 20:59:48 +0000 (21:59 +0100)
committerRich Salz <rsalz@akamai.com>
Fri, 4 Mar 2016 00:47:01 +0000 (19:47 -0500)
Signed-off-by: Rich Salz <rsalz@akamai.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/threads_pthread.c
crypto/threads_win.c

index 2b32e14..edca77c 100644 (file)
@@ -58,8 +58,10 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
     if (lock == NULL)
         return NULL;
 
-    if (pthread_rwlock_init(lock, NULL) != 0)
+    if (pthread_rwlock_init(lock, NULL) != 0) {
+        OPENSSL_free(lock);
         return NULL;
+    }
 
     return lock;
 }
index bee628f..741e8f8 100644 (file)
@@ -59,8 +59,10 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
         return NULL;
 
     /* 0x400 is the spin count value suggested in the documentation */
-    if (!InitializeCriticalSectionAndSpinCount(lock, 0x400))
+    if (!InitializeCriticalSectionAndSpinCount(lock, 0x400)) {
+        OPENSSL_free(lock);
         return NULL;
+    }
 
     return lock;
 }