[PECL-CVS] [pecl-mail-mailparse] master: Fix memory leak
[email protected] (Remi Collet)
| Newsgroups | php.pecl.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Remi Collet (remicollet)
Date: 2025-09-29T16:03:55+02:00
Commit: https://github.com/php/pecl-mail-mailparse/commit/f4c9d92c90c7bfdfc8b3bfe41ff5b18091783f1d
Raw diff: https://github.com/php/pecl-mail-mailparse/commit/f4c9d92c90c7bfdfc8b3bfe41ff5b18091783f1d.diff
Fix memory leak
Changed paths:
M mailparse.c
M package.xml
M php_mailparse_mime.c
Diff:
diff --git a/mailparse.c b/mailparse.c
index d3f5947..5dac132 100644
--- a/mailparse.c
+++ b/mailparse.c
@@ -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()
diff --git a/package.xml b/package.xml
index 2d9f64a..13e37aa 100644
--- a/package.xml
+++ b/package.xml
@@ -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="/">
diff --git a/php_mailparse_mime.c b/php_mailparse_mime.c
index fb92473..87794b0 100644
--- a/php_mailparse_mime.c
+++ b/php_mailparse_mime.c
@@ -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);