Fix memory leak

This commit is contained in:
Remi Collet
2025-09-29 16:03:55 +02:00
parent ae33599c94
commit f4c9d92c90
3 changed files with 10 additions and 3 deletions

View File

@@ -122,9 +122,7 @@ ZEND_RSRC_DTOR_FUNC(mimepart_dtor)
{
php_mimepart *part = res->ptr;
if (part->parent == NULL) {
php_mimepart_free(part);
}
php_mimepart_free(part);
}
PHP_INI_BEGIN()

View File

@@ -48,6 +48,7 @@ It can deal with rfc822 and rfc2045 (MIME) compliant messages.
<license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license>
<notes>
- use Zend/zend_smart_string.h for PHP 8.5
- Fix memory leak
</notes>
<contents>
<dir name="/">

View File

@@ -318,7 +318,15 @@ PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc()
PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part)
{
zval *childpart_z;
HashPosition pos;
/* free contained parts */
zend_hash_internal_pointer_reset_ex(&part->children, &pos);
while ((childpart_z = zend_hash_get_current_data_ex(&part->children, &pos)) != NULL) {
zval_ptr_dtor(childpart_z);
zend_hash_move_forward_ex(&part->children, &pos);
}
zend_hash_destroy(&part->children);