@@ -4321,6 +4321,7 @@ PHP_FUNCTION(openssl_seal)
4321
4321
4322
4322
if (!EVP_EncryptInit (& ctx ,cipher ,NULL ,NULL )) {
4323
4323
RETVAL_FALSE ;
4324
+ EVP_CIPHER_CTX_cleanup (& ctx );
4324
4325
goto clean_exit ;
4325
4326
}
4326
4327
@@ -4331,10 +4332,12 @@ PHP_FUNCTION(openssl_seal)
4331
4332
#endif
4332
4333
/* allocate one byte extra to make room for \0 */
4333
4334
buf = emalloc (data_len + EVP_CIPHER_CTX_block_size (& ctx ));
4335
+ EVP_CIPHER_CTX_cleanup (& ctx );
4334
4336
4335
4337
if (!EVP_SealInit (& ctx , cipher , eks , eksl , NULL , pkeys , nkeys ) || !EVP_SealUpdate (& ctx , buf , & len1 , (unsigned char * )data , data_len )) {
4336
4338
RETVAL_FALSE ;
4337
4339
efree (buf );
4340
+ EVP_CIPHER_CTX_cleanup (& ctx );
4338
4341
goto clean_exit ;
4339
4342
}
4340
4343
@@ -4367,6 +4370,7 @@ PHP_FUNCTION(openssl_seal)
4367
4370
efree (buf );
4368
4371
}
4369
4372
RETVAL_LONG (len1 + len2 );
4373
+ EVP_CIPHER_CTX_cleanup (& ctx );
4370
4374
4371
4375
clean_exit :
4372
4376
for (i = 0 ; i < nkeys ; i ++ ) {
@@ -4425,25 +4429,21 @@ PHP_FUNCTION(openssl_open)
4425
4429
if (EVP_OpenInit (& ctx , cipher , (unsigned char * )ekey , ekey_len , NULL , pkey ) && EVP_OpenUpdate (& ctx , buf , & len1 , (unsigned char * )data , data_len )) {
4426
4430
if (!EVP_OpenFinal (& ctx , buf + len1 , & len2 ) || (len1 + len2 == 0 )) {
4427
4431
efree (buf );
4428
- if (keyresource == -1 ) {
4429
- EVP_PKEY_free (pkey );
4430
- }
4431
- RETURN_FALSE ;
4432
+ RETVAL_FALSE ;
4433
+ } else {
4434
+ zval_dtor (opendata );
4435
+ buf [len1 + len2 ] = '\0' ;
4436
+ ZVAL_STRINGL (opendata , erealloc (buf , len1 + len2 + 1 ), len1 + len2 , 0 );
4437
+ RETVAL_TRUE ;
4432
4438
}
4433
4439
} else {
4434
4440
efree (buf );
4435
- if (keyresource == -1 ) {
4436
- EVP_PKEY_free (pkey );
4437
- }
4438
- RETURN_FALSE ;
4441
+ RETVAL_FALSE ;
4439
4442
}
4440
4443
if (keyresource == -1 ) {
4441
4444
EVP_PKEY_free (pkey );
4442
4445
}
4443
- zval_dtor (opendata );
4444
- buf [len1 + len2 ] = '\0' ;
4445
- ZVAL_STRINGL (opendata , erealloc (buf , len1 + len2 + 1 ), len1 + len2 , 0 );
4446
- RETURN_TRUE ;
4446
+ EVP_CIPHER_CTX_cleanup (& ctx );
4447
4447
}
4448
4448
/* }}} */
4449
4449
0 commit comments