どうもご返事が遅くなってしまい、申し訳ありませんでした。 > メモリ使用量が大きいことに関して: > #if 0 / #if 1を変えることによりサイズは増減しますが、使っている関数 > が異なるので、許容範囲内のようにおもいます。 > > もし、メモリ的にこの使用量が大きすぎるようでしたら、所望の関数を自作 > するか、gethostbyname()を呼んだスレッドを捨てることで解決できそうな > 気がします。 Memcheckというツールを使いメモリリークの調査をしました。 (最後に添付しました。長文お許しください) ここでは、interbase(FireBird)のisc_attach_database()と 自作のConnectHost()内のgethostbyname_r()にてメモリリークが 発生しているように見えます。が、gethostbyname()(glibc)にてそのような 状態になるとは考えにくく呼び元の問題と思っているのですが、理由が つかめ切れないで苦慮しております。 また、該当スレッドが終了してもリークは解消されません。 また、malloc()とcalloc()の混在はよくないとかいろいろ聞いたのですが どうも決め手にかけているように思います。 ==5385== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. ==5385== Copyright (C) 2002, and GNU GPL'd, by Julian Seward. ==5385== Using valgrind-1.9.2, a program instrumentation system for x86-linux. ==5385== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward. ==5385== Startup, with flags: ==5385== --suppressions=/usr/local/lib/valgrind/default.supp ==5385== --leak-check=yes ==5385== --show-reachable=yes ==5385== --workaround-gcc296-bugs=yes ==5385== -v ==5385== --num-callers=40 ==5385== Reading suppressions file: /usr/local/lib/valgrind/default.supp ==5385== Estimated CPU clock rate is 267 MHz ==5385== ==5385== Reading syms from /opt/castserver/castserv ==5385== Reading syms from /lib/ld-2.2.4.so ==5385== Reading syms from /usr/local/lib/valgrind/vgskin_memcheck.so ==5385== Reading syms from /usr/local/lib/valgrind/valgrind.so ==5385== Reading syms from /opt/interbase/lib/libgds.so.0 ==5385== object doesn't have any debug info ==5385== Reading syms from /lib/libcrypt-2.2.4.so ==5385== Reading syms from /lib/i686/libc-2.2.4.so ==5385== Reading syms from /usr/local/lib/valgrind/libpthread.so ==5385== Reading syms from /lib/libnss_files-2.2.4.so ==5385== Reading syms from /lib/libnss_nisplus-2.2.4.so ==5385== Reading syms from /lib/libnsl-2.2.4.so ==5385== Reading syms from /lib/libnss_dns-2.2.4.so ==5385== Reading syms from /lib/libresolv-2.2.4.so ==5385== valgrind's libpthread.so: KLUDGED call to: sem_destroy ==5385== valgrind's libpthread.so: KLUDGED call to: sem_destroy ==5385== valgrind's libpthread.so: KLUDGED call to: pthread_cond_destroy ==5385== ==5385== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 183 from 3) --5385-- --5385-- supp: 15 _dl_relocate_object/libc-2.2.4.so/_dl_catch_error(Cond) --5385-- supp: 86 __pthread_mutex_unlock/_IO_funlockfile --5385-- supp: 82 pthread_error/__pthread_mutex_destroy/_IO_default_finish ==5385== malloc/free: in use at exit: 3999 bytes in 33 blocks. ==5385== malloc/free: 4719 allocs, 4686 frees, 604567 bytes allocated. ==5385== ==5385== searching for pointers to 33 not-freed blocks. ==5385== checked 4428420 bytes. ==5385== ==5385== definitely lost: 0 bytes in 0 blocks. ==5385== possibly lost: 0 bytes in 0 blocks. ==5385== still reachable: 3999 bytes in 33 blocks. ==5385== ==5385== 16 bytes in 2 blocks are still reachable in loss record 1 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x4000C6EA: _dl_map_object_deps (dl-deps.c:467) ==5385== by 0x403B6062: dl_open_worker (dl-open.c:248) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40399010: __nss_next (nsswitch.c:194) ==5385== by 0x403996AC: __nss_endent (getnssent_r.c:117) ==5385== by 0x40356CCC: endpwent (../nss/getXXent_r.c:135) ==5385== by 0x40235B2E: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 22 bytes in 1 blocks are still reachable in loss record 2 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x40323A33: __strdup (strdup.c:43) ==5385== by 0x415558BC: _nss_create_tablename (nss_nisplus/nisplus-hosts.c:188) ==5385== by 0x41555D2C: internal_gethostbyname2_r (nss_nisplus/nisplus-hosts.c:338) ==5385== by 0x41556120: _nss_nisplus_gethostbyname_r (nss_nisplus/nisplus-hosts.c:447) ==5385== by 0x4039B8B2: gethostbyname_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:200) ==5385== by 0x804C7DE: ConnectHost (sock.c:118) ==5385== by 0x804A95E: RequestMain (proxy.c:474) ==5385== by 0x8049FF6: ProxyMain (proxy.c:137) ==5385== by 0x8049DBA: client_thread (main.c:770) ==5385== by 0x8049CBF: ClientMain (main.c:679) ==5385== by 0x8049C5B: MainLoop (main.c:645) ==5385== by 0x80498CB: main (main.c:468) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 28 bytes in 1 blocks are still reachable in loss record 3 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x4160ED89: __res_nsend (res_send.c:440) ==5385== by 0x4160DC56: __res_nquery (res_query.c:132) ==5385== by 0x4160E1E2: __res_nquerydomain (res_query.c:363) ==5385== by 0x4160DE80: __res_nsearch (res_query.c:212) ==5385== by 0x415F1FD6: _nss_dns_gethostbyname2_r (nss_dns/dns-host.c:171) ==5385== by 0x415F3454: _nss_dns_gethostbyname_r (nss_dns/dns-host.c:212) ==5385== by 0x4039B8B2: gethostbyname_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:200) ==5385== by 0x804C7DE: ConnectHost (sock.c:118) ==5385== by 0x804A95E: RequestMain (proxy.c:474) ==5385== by 0x8049FF6: ProxyMain (proxy.c:137) ==5385== by 0x8049DBA: client_thread (main.c:770) ==5385== by 0x8049CBF: ClientMain (main.c:679) ==5385== by 0x8049C5B: MainLoop (main.c:645) ==5385== by 0x80498CB: main (main.c:468) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 100 bytes in 3 blocks are still reachable in loss record 4 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x4000C78D: _dl_map_object_deps (dl-deps.c:495) ==5385== by 0x403B6062: dl_open_worker (dl-open.c:248) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 106 bytes in 5 blocks are still reachable in loss record 5 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x4000AE6B: _dl_new_object (dl-object.c:94) ==5385== by 0x4000651D: _dl_map_object_from_fd (dl-load.c:828) ==5385== by 0x40007C28: _dl_map_object (dl-load.c:1740) ==5385== by 0x403B5FCB: dl_open_worker (dl-open.c:217) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 106 bytes in 5 blocks are still reachable in loss record 6 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x40007F97: _dl_map_object (dl-load.c:164) ==5385== by 0x403B5FCB: dl_open_worker (dl-open.c:217) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 141 bytes in 5 blocks are still reachable in loss record 7 of 10 ==5385== at 0x40168A70: malloc (vg_clientfuncs.c:100) ==5385== by 0x4000AC0D: _dl_new_object (dl-object.c:41) ==5385== by 0x4000651D: _dl_map_object_from_fd (dl-load.c:828) ==5385== by 0x40007C28: _dl_map_object (dl-load.c:1740) ==5385== by 0x403B5FCB: dl_open_worker (dl-open.c:217) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 200 bytes in 1 blocks are still reachable in loss record 8 of 10 ==5385== at 0x403DD0EF: my_malloc (vg_libpthread.c:262) ==5385== by 0x403DEB25: get_or_allocate_specifics_ptr (vg_libpthread.c:1375) ==5385== by 0x403DEC41: __pthread_key_create (vg_libpthread.c:1412) ==5385== by 0x4023AA51: init (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x403DEE51: __pthread_once (vg_libpthread.c:1497) ==5385== by 0x4023A820: THD_put_specific (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E862: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 720 bytes in 5 blocks are still reachable in loss record 9 of 10 ==5385== at 0x40168F5D: calloc (vg_clientfuncs.c:242) ==5385== by 0x4000EBB9: _dl_check_map_versions (dl-version.c:287) ==5385== by 0x403B625E: dl_open_worker (dl-open.c:253) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== 2560 bytes in 5 blocks are still reachable in loss record 10 of 10 ==5385== at 0x40168F5D: calloc (vg_clientfuncs.c:242) ==5385== by 0x4000ABFC: _dl_new_object (dl-object.c:40) ==5385== by 0x4000651D: _dl_map_object_from_fd (dl-load.c:828) ==5385== by 0x40007C28: _dl_map_object (dl-load.c:1740) ==5385== by 0x403B5FCB: dl_open_worker (dl-open.c:217) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B634D: _dl_open (dl-open.c:349) ==5385== by 0x403B70C0: do_dlopen (dl-libc.c:78) ==5385== by 0x4000D712: _dl_catch_error (dl-error.c:152) ==5385== by 0x403B6F6B: __libc_dlopen (dl-libc.c:42) ==5385== by 0x403985EE: __nss_lookup_function (nsswitch.c:340) ==5385== by 0x40398F55: __nss_lookup (nsswitch.c:147) ==5385== by 0x4039A04B: __nss_passwd_lookup (XXX-lookup.c:70) ==5385== by 0x40357146: getpwuid_r@@GLIBC_2.1.2 (../nss/getXXbyYY_r.c:168) ==5385== by 0x40356ABA: getpwuid (../nss/getXXbyYY.c:131) ==5385== by 0x40235B18: ISC_get_user (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024B47B: INET_analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x40254565: analyze (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4024E984: REM_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x4023CFF0: isc_attach_database (in /opt/interbase/lib/libgds.so.0) ==5385== by 0x804F733: db_connect (dbfunc.c:1382) ==5385== by 0x80497FE: main (main.c:431) ==5385== by 0x402B9506: __libc_start_main (../sysdeps/generic/libc-start.c:129) ==5385== by 0x8049590: (within /opt/castserver/castserv) ==5385== ==5385== LEAK SUMMARY: ==5385== definitely lost: 0 bytes in 0 blocks. ==5385== possibly lost: 0 bytes in 0 blocks. ==5385== still reachable: 3999 bytes in 33 blocks. ==5385== --5385-- TT/TC: 0 tc sectors discarded. --5385-- 6180 chainings, 0 unchainings. --5385-- translate: new 8629 (135782 -> 1821766; ratio 134:10) --5385-- discard 0 (0 -> 0; ratio 0:10). --5385-- dispatch: 4250000 jumps (bb entries), of which 1662346 (39%) were unchained. --5385-- 6857/389470 major/minor sched events. 22084 tt_fast misses. --5385-- reg-alloc: 1174 t-req-spill, 339193+10100 orig+spill uis, 42274 total-reg-r. --5385-- sanity: 3471 cheap, 139 expensive checks. --5385-- ccalls: 38652 C calls, 56% saves+restores avoided (127666 bytes) --5385-- 50499 args, avg 0.89 setup instrs each (11088 bytes) --5385-- 0% clear the stack (115956 bytes) --5385-- 13156 retvals, 30% of reg-reg movs avoided (7830 bytes) -- 近藤 正博 <echo@xxxxxxxxxxxxxxx>