Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for memory leaks in CI #31

Closed
rtheunissen opened this issue Aug 3, 2016 · 6 comments
Closed

Check for memory leaks in CI #31

rtheunissen opened this issue Aug 3, 2016 · 6 comments

Comments

@rtheunissen
Copy link
Member

What's the best way to do this?

@nikic
Copy link
Contributor

nikic commented Aug 3, 2016

Apart from using a debug PHP build, you'd also have to patch phpunit to not use exit, otherwise you're not going to get any leak reports.

@rtheunissen
Copy link
Member Author

This seems to be working now. I'll create a leak and verify that it fails.

composer memtest

@rtheunissen
Copy link
Member Author

Nope.

@rtheunissen
Copy link
Member Author

I've disabled the memory test for now to get a passing build.

@rtheunissen
Copy link
Member Author

rtheunissen commented Aug 5, 2016

Here is the valgrind report for the most recent build that failed the memory test:

$ composer memtest
> USE_ZEND_ALLOC=0 ZEND_DONT_UNLOAD_MODULES=1 valgrind php ./vendor/bin/phpunit -c ./vendor/php-ds/tests/phpunit.xml
==10874== Memcheck, a memory error detector
==10874== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==10874== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==10874== Command: php ./vendor/bin/phpunit -c ./vendor/php-ds/tests/phpunit.xml
==10874== 
==10874== 
==10874== HEAP SUMMARY:
==10874==     in use at exit: 25,763 bytes in 223 blocks
==10874==   total heap usage: 2,610,963 allocs, 2,610,740 frees, 6,700,558,612 bytes allocated
==10874== 
==10874== 56 bytes in 1 blocks are definitely lost in loss record 52 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x9048CE: zend_objects_new (zend_objects.c:162)
==10874==    by 0x8CE90D: _object_and_properties_init (zend_API.c:1301)
==10874==    by 0x9631FC: ZEND_NEW_SPEC_VAR_HANDLER (zend_vm_execute.h:15415)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x8BBFDB: zend_call_function (zend_execute_API.c:866)
==10874==    by 0x70F1EA: zim_reflection_method_invokeArgs (php_reflection.c:3348)
==10874==    by 0x956AE6: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874== 
==10874== 56 bytes in 1 blocks are definitely lost in loss record 53 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8C8FDB: _zval_copy_ctor_func (zend_string.h:121)
==10874==    by 0x911812: ZEND_ASSIGN_SPEC_CV_CONST_HANDLER (zend_execute.h:119)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874==    by 0x96810D: do_cli (php_cli.c:974)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== 64 bytes in 1 blocks are definitely lost in loss record 57 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8A383F: _ecalloc (zend_alloc.c:2541)
==10874==    by 0xF2B550F: php_ds_map_create_object_ex (php_map.c:11)
==10874==    by 0x8CE8EA: _object_and_properties_init (zend_API.c:1308)
==10874==    by 0x963433: ZEND_NEW_SPEC_CONST_HANDLER (zend_vm_execute.h:3342)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x8BBFDB: zend_call_function (zend_execute_API.c:866)
==10874==    by 0x70F1EA: zim_reflection_method_invokeArgs (php_reflection.c:3348)
==10874==    by 0x956AE6: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874== 
==10874== 104 bytes in 1 blocks are definitely lost in loss record 68 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x9048CE: zend_objects_new (zend_objects.c:162)
==10874==    by 0x8CE90D: _object_and_properties_init (zend_API.c:1301)
==10874==    by 0x9631FC: ZEND_NEW_SPEC_VAR_HANDLER (zend_vm_execute.h:15415)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874==    by 0x96810D: do_cli (php_cli.c:974)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== 128 bytes in 2 blocks are definitely lost in loss record 71 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8A383F: _ecalloc (zend_alloc.c:2541)
==10874==    by 0xF2B6C6F: php_ds_set_create_object_ex (php_set.c:9)
==10874==    by 0x8CE8EA: _object_and_properties_init (zend_API.c:1308)
==10874==    by 0x963433: ZEND_NEW_SPEC_CONST_HANDLER (zend_vm_execute.h:3342)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x8BBFDB: zend_call_function (zend_execute_API.c:866)
==10874==    by 0x70F1EA: zim_reflection_method_invokeArgs (php_reflection.c:3348)
==10874==    by 0x956AE6: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874== 
==10874== 256 bytes in 4 blocks are definitely lost in loss record 76 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8A383F: _ecalloc (zend_alloc.c:2541)
==10874==    by 0xF2B46FF: php_ds_vector_create_object_ex (php_vector.c:9)
==10874==    by 0x8CE8EA: _object_and_properties_init (zend_API.c:1308)
==10874==    by 0x963433: ZEND_NEW_SPEC_CONST_HANDLER (zend_vm_execute.h:3342)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x8BBFDB: zend_call_function (zend_execute_API.c:866)
==10874==    by 0x70F1EA: zim_reflection_method_invokeArgs (php_reflection.c:3348)
==10874==    by 0x956AE6: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874== 
==10874== 464 (56 direct, 408 indirect) bytes in 1 blocks are definitely lost in loss record 87 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8CDDF7: _array_init (zend_API.c:1061)
==10874==    by 0x86EC52: php_build_argv (php_variables.c:537)
==10874==    by 0x86F5E9: php_hash_environment (php_variables.c:666)
==10874==    by 0x85D668: php_request_startup (main.c:1628)
==10874==    by 0x967ABE: do_cli (php_cli.c:945)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== 872 (640 direct, 232 indirect) bytes in 2 blocks are definitely lost in loss record 95 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x9048CE: zend_objects_new (zend_objects.c:162)
==10874==    by 0x8CE90D: _object_and_properties_init (zend_API.c:1301)
==10874==    by 0x963433: ZEND_NEW_SPEC_CONST_HANDLER (zend_vm_execute.h:3342)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874==    by 0x96810D: do_cli (php_cli.c:974)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== 4,560 (224 direct, 4,336 indirect) bytes in 1 blocks are definitely lost in loss record 102 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x8894D0: compile_file (zend_language_scanner.l:596)
==10874==    by 0x6EE37D: phar_compile_file (phar.c:3322)
==10874==    by 0x8CB85F: zend_execute_scripts (zend.c:1421)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874==    by 0x96810D: do_cli (php_cli.c:974)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== 5,504 (24 direct, 5,480 indirect) bytes in 1 blocks are definitely lost in loss record 103 of 103
==10874==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10874==    by 0x90F98A: ZEND_SEND_REF_SPEC_CV_HANDLER (zend_vm_execute.h:28911)
==10874==    by 0x90E2CF: execute_ex (zend_vm_execute.h:417)
==10874==    by 0x966396: zend_execute (zend_vm_execute.h:458)
==10874==    by 0x8CB8C3: zend_execute_scripts (zend.c:1427)
==10874==    by 0x85F6F5: php_execute_script (main.c:2494)
==10874==    by 0x96810D: do_cli (php_cli.c:974)
==10874==    by 0x456EB4: main (php_cli.c:1344)
==10874== 
==10874== LEAK SUMMARY:
==10874==    definitely lost: 1,608 bytes in 15 blocks
==10874==    indirectly lost: 10,456 bytes in 111 blocks
==10874==      possibly lost: 0 bytes in 0 blocks
==10874==    still reachable: 13,699 bytes in 97 blocks
==10874==         suppressed: 0 bytes in 0 blocks
==10874== Reachable blocks (those to which a pointer was found) are not shown.
==10874== To see them, rerun with: --leak-check=full --show-reachable=yes
==10874== 
==10874== For counts of detected and suppressed errors, rerun with: -v
==10874== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 2 from 2)

@rtheunissen
Copy link
Member Author

I've added a new test script: https://github.com/php-ds/extension/blob/master/test.php
Valgrind options: https://github.com/php-ds/extension/blob/master/.valgrindrc
Travis suppression: https://github.com/php-ds/extension/blob/master/.travis.supp

I don't know why valgrind on Travis is reporting that leak when it doesn't come up on either my OS X machine or on a brand new Ubuntu build. ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants