Fix a possible memory leak in engine_table_register
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 2 Mar 2018 08:27:39 +0000 (09:27 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 3 Mar 2018 19:00:18 +0000 (20:00 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5489)

(cherry picked from commit 55a7f77d72930f9aee1a51e0af9658b2728be127)

crypto/engine/eng_table.c

index 27d31f70c855440ab30984bdb0b9702335eb3d93..5049fd679e7cf4c866fffce688f94edb159103ca 100644 (file)
@@ -159,6 +159,11 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
             }
             fnd->funct = NULL;
             (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd);
+            if (lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate) != fnd) {
+                sk_ENGINE_free(fnd->sk);
+                OPENSSL_free(fnd);
+                goto end;
+            }
         }
         /* A registration shouldn't add duplciate entries */
         (void)sk_ENGINE_delete_ptr(fnd->sk, e);