Skip to content

Commit

Permalink
zend_list_delete -> zend_list_close
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Jan 28, 2016
1 parent ace2bcd commit f2b4423
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mailparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ PHP_FUNCTION(mailparse_msg_free)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg) == FAILURE) {
RETURN_FALSE;
}
zend_list_delete(Z_RES_P(arg));
zend_list_close(Z_RES_P(arg));

This comment has been minimized.

Copy link
@ho-dieu-it

ho-dieu-it Feb 27, 2017

I tested with php script

----------- run test -----------
function parse(){
$mm = new MimeMessage( 'file', 'mailsource.eml' );
}
var_dump(memory_get_usage());
for($i=0;$i<100000;$i++)
{
if($i%1000==0)
var_dump(memory_get_usage());
parse();
}
var_dump(memory_get_usage());
gc_collect_cycles();
var_dump(memory_get_usage());

-> Memory increment continuously.
I think it cause memory leak.
I changed zend_list_close -> zend_list_delete. It's ok.
Please consider this problem. Thank you.

This comment has been minimized.

Copy link
@Sean-Der

Sean-Der Apr 24, 2017

Author Contributor

Hi @ho-dieu-it

I can confirm your memory leak with memory_get_usage however valgrind doesn't report a leak. With your change running the test suite with valgrind reports invalid reads/writes. You can see these by doing make test TESTS=-m in the mailparse repo. You will then get .mem files in the test directory.

I will try my best to find a fix to this, however I don't do much PHP work lately.

==6573== Invalid read of size 4
==6573==    at 0x7195FE: i_zval_ptr_dtor (zend_variables.h:48)
==6573==    by 0x719CB0: _zval_ptr_dtor_wrapper (zend_variables.c:203)
==6573==    by 0x731E31: _zend_hash_del_el_ex (zend_hash.c:997)
==6573==    by 0x731F11: _zend_hash_del_el (zend_hash.c:1020)
==6573==    by 0x73341E: zend_hash_graceful_reverse_destroy (zend_hash.c:1476)
==6573==    by 0x7022B1: shutdown_executor (zend_execute_API.c:281)
==6573==    by 0x71BEB6: zend_deactivate (zend.c:1060)
==6573==    by 0x68B481: php_request_shutdown (main.c:1879)
==6573==    by 0x80233F: do_cli (php_cli.c:1164)
==6573==    by 0x802B3F: main (php_cli.c:1390)
==6573==  Address 0x5b6b000 is 0 bytes inside a block of size 24 free'd
==6573==    at 0x4C2ECB0: free (vg_replace_malloc.c:530)
==6573==    by 0x6E6081: _efree (zend_alloc.c:2428)
==6573==    by 0x736DB9: list_entry_destructor (zend_list.c:189)
==6573==    by 0x731E31: _zend_hash_del_el_ex (zend_hash.c:997)
==6573==    by 0x732745: zend_hash_index_del (zend_hash.c:1198)
==6573==    by 0x7368B8: zend_list_free (zend_list.c:59)
==6573==    by 0x719744: _zval_dtor_func (zend_variables.c:63)
==6573==    by 0x7753B1: zend_vm_stack_free_args (zend_execute.h:253)
==6573==    by 0x77D1EA: ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:631)
==6573==    by 0x77CB2A: execute_ex (zend_vm_execute.h:429)
==6573==    by 0x77CC0B: zend_execute (zend_vm_execute.h:474)
==6573==    by 0x71D306: zend_execute_scripts (zend.c:1537)
==6573==  Block was alloc'd at
==6573==    at 0x4C2DBB6: malloc (vg_replace_malloc.c:299)
==6573==    by 0x6E6CA5: __zend_malloc (zend_alloc.c:2811)
==6573==    by 0x6E5FDA: _emalloc (zend_alloc.c:2413)
==6573==    by 0x7367BA: zend_list_insert (zend_list.c:43)
==6573==    by 0x7369DB: zend_register_resource (zend_list.c:98)
==6573==    by 0x5D338E9: php_mimepart_alloc (php_mailparse_mime.c:320)
==6573==    by 0x5D312B2: zif_mailparse_msg_parse_file (mailparse.c:1072)
==6573==    by 0x77D304: ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:664)
==6573==    by 0x77CB2A: execute_ex (zend_vm_execute.h:429)
==6573==    by 0x77CC0B: zend_execute (zend_vm_execute.h:474)
==6573==    by 0x71D306: zend_execute_scripts (zend.c:1537)
==6573==    by 0x68C7C8: php_execute_script (main.c:2548)
RETURN_TRUE;
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion php_mailparse_mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc()
PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part)
{
if (part->rsrc) {
zend_list_delete(part->rsrc);
zend_list_close(part->rsrc);
part->rsrc = NULL;
}

Expand Down

0 comments on commit f2b4423

Please sign in to comment.