Re: debugging with valgrind
| From: | Swithun Crowe | Date: | Tue, 03 Aug 2004 15:07:41 +0000 |
| Subject: | Re: debugging with valgrind | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-1080@lists.php.net to get a copy of this message | ||
Hello
Thanks for the tip on valgrind - a very informative tool. It reports a
lot of lost memory in one of the libraries I'm using with my C++
extension. Following the code there, it looks like the memory gets freed,
but not immediately nor within the same bit of code. Do you know if this
is the sort of thing that can confuse valgrind? (I've put some output
below.)
I'm worried because when I run a PHP script using my extension with a web
server, the server (apache and thttpd) accumulates memory - at first a
lot, then it slows down but doesn't stop growing.
I've been using J Smith's tutorial as a starting point, but have modified
some of the destructor functions. Where the tutorial says:
static void php5cpp_object_free_storage(zend_object *object TSRMLS_DC)
{
php5cpp_obj *obj = (php5cpp_obj *) object;
zend_hash_destroy(obj->std.properties);
FREE_HASHTABLE(obj->std.properties);
if (obj->u.myclass) {
zend_list_delete(obj->rsrc_id);
}
efree(obj);
}
I've added a couple of lines so that it would now read:
if (obj->u.myclass) {
zend_list_delete(obj->rsrc_id);
delete (MyClass *) obj->u.myclass; /* added by me */
obj->u.myclass = NULL; /* ditto */
}
Is memory build-up just something that happens (curable with a
MaxRequestsPerChild in apache)? Or is there any way to get more memory
freed after each script is run? I think I'm following the PHP5/C++
tutorial fairly closely, but I could supply some of my code if anyone
thinks it would be worth a look.
Below is the output from valgrind.
Thanks again.
Swithun.
==15256== Memcheck, a.k.a. Valgrind, a memory error detector for
x86-linux.
==15256== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==15256== Using valgrind-2.0.0, a program supervision framework for
x86-linux.
==15256== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==15256== Command line:
==15256== thttpd
==15256== -D
==15256== -d
==15256== /home/web/public_html
==15256== -p
==15256== 8080
==15256== -nos
==15256== Startup, with flags:
==15256== --suppressions=/usr/local/lib/valgrind/default.supp
==15256== -v
==15256== --num-callers=50
==15256== --trace-children=yes
==15256== --leak-check=yes
==15256== --leak-resolution=high
==15256== Reading syms from /usr/local/sbin/thttpd
==15256== Reading syms from /lib/ld-2.3.1.so
==15256== Reading syms from /usr/local/lib/valgrind/vgskin_memcheck.so
==15256== Reading syms from /usr/local/lib/valgrind/valgrind.so
==15256== Reading syms from /lib/libcrypt-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /lib/libresolv-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /lib/libm-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /lib/libdl-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /lib/libnsl-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /usr/local/lib/libxml2.so.2.6.4
==15256== Reading syms from /usr/lib/libz.so.1.1.4
==15256== object doesn't have a symbol table
==15256== object doesn't have any debug info
==15256== Reading syms from /usr/lib/libstdc++.so.5.0.2
==15256== object doesn't have a symbol table
==15256== object doesn't have any debug info
==15256== Reading syms from /usr/local/lib/libxerces-c.so.24.0
==15256== Reading syms from
/usr/local/BerkeleyDBXML.1.2/lib/libdbxml-1.2.so
==15256== Reading syms from /usr/local/BerkeleyDB.4.2/lib/libdb-4.2.so
==15256== Reading syms from /usr/local/BerkeleyDB.4.2/lib/libdb_cxx-4.2.so
==15256== Reading syms from /usr/local/lib/libpathan.so.2.0.2
==15256== Reading syms from /lib/libc-2.3.1.so
==15256== object doesn't have any debug info
==15256== Reading syms from /usr/local/lib/valgrind/libpthread.so
==15256== Reading syms from /usr/lib/libgcc_s.so.1
==15256== object doesn't have a symbol table
==15256== object doesn't have any debug info
==15256== Reading suppressions file: /usr/local/lib/valgrind/default.supp
==15256== Estimated CPU clock rate is 666 MHz
==15256== REPLACING libc(__errno_location) with
libpthread(__errno_location)
==15256== REPLACING libc(__h_errno_location) with
libpthread(__h_errno_location)
==15256== REPLACING libc(__res_state) with libpthread(__res_state)
==15256==
==15256== Reading syms from /lib/libnss_compat-2.3.1.so
==15256== object doesn't have any debug info
==15256== Conditional jump or move depends on uninitialised value(s)
==15256== at 0x40008C90: elf_dynamic_do_rela.8 (do-rel.h:104)
==15256== by 0x40008F3A: _dl_relocate_object_internal (dl-reloc.c:164)
==15256== by 0x40BDBFD8: dl_open_worker (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDC23E: __GI__dl_open (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCF08: do_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDCEAD: dlerror_run (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCFD7: __libc_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x40BBD0EC: __nss_lookup_function (in /lib/libc-2.3.1.so)
==15256== by 0x40BBCCDA: __nss_lookup (in /lib/libc-2.3.1.so)
==15256== by 0x40BBEE94: __GI___nss_passwd_lookup (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D6CA: getpwnam_r@@GLIBC_2.1.2 (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D08E: getpwnam (in /lib/libc-2.3.1.so)
==15256== by 0x8073FE5: main (thttpd.c:312)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256== Conditional jump or move depends on uninitialised value(s)
==15256== at 0x40008CCA: elf_dynamic_do_rela.8 (do-rel.h:117)
==15256== by 0x40008F3A: _dl_relocate_object_internal (dl-reloc.c:164)
==15256== by 0x40BDBFD8: dl_open_worker (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDC23E: __GI__dl_open (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCF08: do_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDCEAD: dlerror_run (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCFD7: __libc_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x40BBD0EC: __nss_lookup_function (in /lib/libc-2.3.1.so)
==15256== by 0x40BBCCDA: __nss_lookup (in /lib/libc-2.3.1.so)
==15256== by 0x40BBEE94: __GI___nss_passwd_lookup (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D6CA: getpwnam_r@@GLIBC_2.1.2 (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D08E: getpwnam (in /lib/libc-2.3.1.so)
==15256== by 0x8073FE5: main (thttpd.c:312)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 18 from 2)
==15256==
==15256== 1 errors in context 1 of 2:
==15256== Conditional jump or move depends on uninitialised value(s)
==15256== at 0x40008CCA: elf_dynamic_do_rela.8 (do-rel.h:117)
==15256== by 0x40008F3A: _dl_relocate_object_internal (dl-reloc.c:164)
==15256== by 0x40BDBFD8: dl_open_worker (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDC23E: __GI__dl_open (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCF08: do_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDCEAD: dlerror_run (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCFD7: __libc_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x40BBD0EC: __nss_lookup_function (in /lib/libc-2.3.1.so)
==15256== by 0x40BBCCDA: __nss_lookup (in /lib/libc-2.3.1.so)
==15256== by 0x40BBEE94: __GI___nss_passwd_lookup (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D6CA: getpwnam_r@@GLIBC_2.1.2 (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D08E: getpwnam (in /lib/libc-2.3.1.so)
==15256== by 0x8073FE5: main (thttpd.c:312)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256== 1 errors in context 2 of 2:
==15256== Conditional jump or move depends on uninitialised value(s)
==15256== at 0x40008C90: elf_dynamic_do_rela.8 (do-rel.h:104)
==15256== by 0x40008F3A: _dl_relocate_object_internal (dl-reloc.c:164)
==15256== by 0x40BDBFD8: dl_open_worker (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDC23E: __GI__dl_open (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCF08: do_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x4000A8B5: _dl_catch_error_internal (dl-error.c:159)
==15256== by 0x40BDCEAD: dlerror_run (in /lib/libc-2.3.1.so)
==15256== by 0x40BDCFD7: __libc_dlopen (in /lib/libc-2.3.1.so)
==15256== by 0x40BBD0EC: __nss_lookup_function (in /lib/libc-2.3.1.so)
==15256== by 0x40BBCCDA: __nss_lookup (in /lib/libc-2.3.1.so)
==15256== by 0x40BBEE94: __GI___nss_passwd_lookup (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D6CA: getpwnam_r@@GLIBC_2.1.2 (in
/lib/libc-2.3.1.so)
==15256== by 0x40B7D08E: getpwnam (in /lib/libc-2.3.1.so)
==15256== by 0x8073FE5: main (thttpd.c:312)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
... I pressed ^C after a few requests ...
--15256--
--15256-- supp: 16 __pthread_mutex_unlock/_IO_funlockfile
--15256-- supp: 2
pthread_error/__pthread_mutex_destroy/_IO_default_finish
==15256==
==15256== IN SUMMARY: 2 errors from 2 contexts (suppressed: 18 from 2)
==15256==
==15256== malloc/free: in use at exit: 199211 bytes in 2268 blocks.
==15256== malloc/free: 51555 allocs, 49287 frees, 76051034 bytes
allocated.
==15256==
==15256== searching for pointers to 2268 not-freed blocks.
==15256== checked 14547216 bytes.
==15256==
==15256==
==15256== 280 bytes in 5 blocks are possibly lost in loss record 27 of 45
==15256== at 0x4002888E: __builtin_vec_new (vg_replace_malloc.c:203)
==15256== by 0x400288E5: operator new[](unsigned)
(vg_replace_malloc.c:216)
==15256== by 0x40A94233: v2Utils::escapeString(unsigned short const*,
bool) (in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A946F0: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A945A4: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A945A4: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x4084E517: DbXml::NodeValue::asString(DbXml::QueryContext
const*) const (../src/dbxml/Value.cpp:209)
==15256== by 0x408B1949:
DbXml::XmlValue::asString(DbXml::XmlQueryContext const*) const
(../src/dbxml/XmlValue.cpp:225)
==15256== by 0x8129C80: zif_mydbxml_xmlvalue_as_string(int,
_zval_struct*, _zval_struct*, int)
(/home/swithun/php-5.0.0/ext/mydbxml/mydbxml.cpp:1877)
==15256== by 0x810CD5B: zend_do_fcall_common_helper
(/home/swithun/php-5.0.0/Zend/zend_execute.c:2699)
==15256== by 0x810A38D: execute
(/home/swithun/php-5.0.0/Zend/zend_execute.c:1391)
==15256== by 0x80F4C5A: zend_execute_scripts
(/home/swithun/php-5.0.0/Zend/zend.c:1061)
==15256== by 0x80CCAFA: php_execute_script
(/home/swithun/php-5.0.0/main/main.c:1627)
==15256== by 0x80820B6: thttpd_module_main (php_thttpd.c:427)
==15256== by 0x808253B: thttpd_real_php_request (php_thttpd.c:670)
==15256== by 0x807D801: really_start_request (libhttpd.c:3713)
==15256== by 0x807604C: boot_request (thttpd.c:1548)
==15256== by 0x8074651: main (thttpd.c:617)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256==
==15256== 292 bytes in 4 blocks are possibly lost in loss record 28 of 45
==15256== at 0x4002888E: __builtin_vec_new (vg_replace_malloc.c:203)
==15256== by 0x400288E5: operator new[](unsigned)
(vg_replace_malloc.c:216)
==15256== by 0x40A94233: v2Utils::escapeString(unsigned short const*,
bool) (in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A94651: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x4084E517: DbXml::NodeValue::asString(DbXml::QueryContext
const*) const (../src/dbxml/Value.cpp:209)
==15256== by 0x408B1949:
DbXml::XmlValue::asString(DbXml::XmlQueryContext const*) const
(../src/dbxml/XmlValue.cpp:225)
==15256== by 0x8129C80: zif_mydbxml_xmlvalue_as_string(int,
_zval_struct*, _zval_struct*, int)
(/home/swithun/php-5.0.0/ext/mydbxml/mydbxml.cpp:1877)
==15256== by 0x810CD5B: zend_do_fcall_common_helper
(/home/swithun/php-5.0.0/Zend/zend_execute.c:2699)
==15256== by 0x810A38D: execute
(/home/swithun/php-5.0.0/Zend/zend_execute.c:1391)
==15256== by 0x80F4C5A: zend_execute_scripts
(/home/swithun/php-5.0.0/Zend/zend.c:1061)
==15256== by 0x80CCAFA: php_execute_script
(/home/swithun/php-5.0.0/main/main.c:1627)
==15256== by 0x80820B6: thttpd_module_main (php_thttpd.c:427)
==15256== by 0x808253B: thttpd_real_php_request (php_thttpd.c:670)
==15256== by 0x807D801: really_start_request (libhttpd.c:3713)
==15256== by 0x807604C: boot_request (thttpd.c:1548)
==15256== by 0x8074651: main (thttpd.c:617)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256==
==15256== 78624 bytes in 1404 blocks are definitely lost in loss record 44
of 45
==15256== at 0x4002888E: __builtin_vec_new (vg_replace_malloc.c:203)
==15256== by 0x400288E5: operator new[](unsigned)
(vg_replace_malloc.c:216)
==15256== by 0x40A94233: v2Utils::escapeString(unsigned short const*,
bool) (in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A946F0: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A945A4: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A945A4: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x4084E517: DbXml::NodeValue::asString(DbXml::QueryContext
const*) const (../src/dbxml/Value.cpp:209)
==15256== by 0x408B1949:
DbXml::XmlValue::asString(DbXml::XmlQueryContext const*) const
(../src/dbxml/XmlValue.cpp:225)
==15256== by 0x8129C80: zif_mydbxml_xmlvalue_as_string(int,
_zval_struct*, _zval_struct*, int)
(/home/swithun/php-5.0.0/ext/mydbxml/mydbxml.cpp:1877)
==15256== by 0x810CD5B: zend_do_fcall_common_helper
(/home/swithun/php-5.0.0/Zend/zend_execute.c:2699)
==15256== by 0x810A38D: execute
(/home/swithun/php-5.0.0/Zend/zend_execute.c:1391)
==15256== by 0x80F4C5A: zend_execute_scripts
(/home/swithun/php-5.0.0/Zend/zend.c:1061)
==15256== by 0x80CCAFA: php_execute_script
(/home/swithun/php-5.0.0/main/main.c:1627)
==15256== by 0x80820B6: thttpd_module_main (php_thttpd.c:427)
==15256== by 0x808253B: thttpd_real_php_request (php_thttpd.c:670)
==15256== by 0x807D801: really_start_request (libhttpd.c:3713)
==15256== by 0x807604C: boot_request (thttpd.c:1548)
==15256== by 0x8074651: main (thttpd.c:617)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256==
==15256== 81028 bytes in 811 blocks are definitely lost in loss record 45
of 45
==15256== at 0x4002888E: __builtin_vec_new (vg_replace_malloc.c:203)
==15256== by 0x400288E5: operator new[](unsigned)
(vg_replace_malloc.c:216)
==15256== by 0x40A94233: v2Utils::escapeString(unsigned short const*,
bool) (in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x40A94651: v2Utils::serialiseNode(xercesc_2_4::DOMNode*)
(in /usr/local/lib/libpathan.so.2.0.2)
==15256== by 0x4084E517: DbXml::NodeValue::asString(DbXml::QueryContext
const*) const (../src/dbxml/Value.cpp:209)
==15256== by 0x408B1949:
DbXml::XmlValue::asString(DbXml::XmlQueryContext const*) const
(../src/dbxml/XmlValue.cpp:225)
==15256== by 0x8129C80: zif_mydbxml_xmlvalue_as_string(int,
_zval_struct*, _zval_struct*, int)
(/home/swithun/php-5.0.0/ext/mydbxml/mydbxml.cpp:1877)
==15256== by 0x810CD5B: zend_do_fcall_common_helper
(/home/swithun/php-5.0.0/Zend/zend_execute.c:2699)
==15256== by 0x810A38D: execute
(/home/swithun/php-5.0.0/Zend/zend_execute.c:1391)
==15256== by 0x80F4C5A: zend_execute_scripts
(/home/swithun/php-5.0.0/Zend/zend.c:1061)
==15256== by 0x80CCAFA: php_execute_script
(/home/swithun/php-5.0.0/main/main.c:1627)
==15256== by 0x80820B6: thttpd_module_main (php_thttpd.c:427)
==15256== by 0x808253B: thttpd_real_php_request (php_thttpd.c:670)
==15256== by 0x807D801: really_start_request (libhttpd.c:3713)
==15256== by 0x807604C: boot_request (thttpd.c:1548)
==15256== by 0x8074651: main (thttpd.c:617)
==15256== by 0x40AE5BB3: __libc_start_main (in /lib/libc-2.3.1.so)
==15256== by 0x8073D38: (within /usr/local/sbin/thttpd)
==15256==
==15256== LEAK SUMMARY:
==15256== definitely lost: 159652 bytes in 2215 blocks.
==15256== possibly lost: 572 bytes in 9 blocks.
==15256== still reachable: 38787 bytes in 43 blocks.
==15256== suppressed: 200 bytes in 1 blocks.
==15256== Reachable blocks (those to which a pointer was found) are not
shown.
==15256== To see them, rerun with: --show-reachable=yes
==15256==
--15256-- TT/TC: 0 tc sectors discarded.
--15256-- 24020 chainings, 0 unchainings.
--15256-- translate: new 34579 (549130 -> 7803949; ratio 142:10)
--15256-- discard 0 (0 -> 0; ratio 0:10).
--15256-- dispatch: 19700000 jumps (bb entries), of which 4787198 (24%)
were unchained.
--15256-- 3999/361774 major/minor sched events. 126607 tt_fast
misses.
--15256-- reg-alloc: 5294 t-req-spill, 1469945+26577 orig+spill uis,
174064 total-reg-r.
--15256-- sanity: 1662 cheap, 67 expensive checks.
--15256-- ccalls: 188284 C calls, 55% saves+restores avoided (619696
bytes)
--15256-- 249283 args, avg 0.89 setup instrs each (51894 bytes)
--15256-- 0% clear the stack (564852 bytes)
--15256-- 54420 retvals, 32% of reg-reg movs avoided (34022
bytes)