From b9737aa08ea2228e23b3f9289189a14a7cfda800 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 2 Mar 2014 23:26:46 +0100 Subject: [PATCH] Call mcrypt_module_close on error --- ext/mcrypt/mcrypt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c index a9f34d77f5..a8dbc4203a 100644 --- a/ext/mcrypt/mcrypt.c +++ b/ext/mcrypt/mcrypt.c @@ -1268,6 +1268,7 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons /* Checking for key-length */ if (php_mcrypt_ensure_valid_key_size(td, key_len TSRMLS_CC) == FAILURE) { + mcrypt_module_close(td); RETURN_FALSE; } @@ -1275,11 +1276,13 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons if (mcrypt_enc_mode_has_iv(td) == 1) { if (!iv) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Encryption mode requires an initialization vector"); + mcrypt_module_close(td); RETURN_FALSE; } if (iv_len != mcrypt_enc_get_iv_size(td)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE); + mcrypt_module_close(td); RETURN_FALSE; } } @@ -1299,6 +1302,7 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons if (mcrypt_generic_init(td, (void *) key, key_len, (void *) iv) < 0) { php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Mcrypt initialisation failed"); + mcrypt_module_close(td); RETURN_FALSE; } -- 2.50.1