утечки памяти при динамической загрузке ДЛЛ
От: Graf Alex Украина http://grafalex.oberon.kiev.ua
Дата: 21.08.08 09:25
Оценка:
Система Fedora Core 6, glibc 2.5, gcc 4.1.1


#include <stdio.h>
#include <dlfcn.h>

typedef int (* func_t)(int);

int main()
{
    void * pDLL = dlopen("/lib/libc-2.5.so", RTLD_LAZY);
    func_t pFunc = (func_t)dlsym(pDLL, "isdigit");

    printf("isdigit('A') = %d\n", pFunc('A'));
    printf("isdigit('1') = %d\n", pFunc('1'));

    dlclose(pDLL);

    return 0;
}



$ g++ -o dlltest dlltest.cpp -ldl
$ valgrind --tool=memcheck --show-reachable=yes --leak-check=full --num-callers=100 ./dlltest
==1375== Memcheck, a memory error detector.
==1375== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==1375== Using LibVEX rev 1658, a library for dynamic binary translation.
==1375== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==1375== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==1375== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==1375== For more details, rerun with: -v
==1375==
isdigit('A') = 0
isdigit('1') = 2048
==1375==
==1375== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 16 from 1)
==1375== malloc/free: in use at exit: 20 bytes in 1 blocks.
==1375== malloc/free: 3 allocs, 2 frees, 66 bytes allocated.
==1375== For counts of detected errors, rerun with: -v
==1375== searching for pointers to 1 not-freed blocks.
==1375== checked 92,096 bytes.
==1375==
==1375== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==1375== at 0x4005400: malloc (vg_replace_malloc.c:149)
==1375== by 0x4BA8CA38: _dl_map_object_deps (in /lib/ld-2.5.so)
==1375== by 0x4BA916C4: dl_open_worker (in /lib/ld-2.5.so)
==1375== by 0x4BA8DC05: _dl_catch_error (in /lib/ld-2.5.so)
==1375== by 0x4BA91191: _dl_open (in /lib/ld-2.5.so)
==1375== by 0x4C5BBD0C: dlopen_doit (in /lib/libdl-2.5.so)
==1375== by 0x4BA8DC05: _dl_catch_error (in /lib/ld-2.5.so)
==1375== by 0x4C5BC38B: _dlerror_run (in /lib/libdl-2.5.so)
==1375== by 0x4C5BBC43: dlopen@@GLIBC_2.1 (in /lib/libdl-2.5.so)
==1375== by 0x8048528: main (in /home/grafalex/work/tests/DLLTest/dlltest)
==1375==
==1375== LEAK SUMMARY:
==1375== definitely lost: 0 bytes in 0 blocks.
==1375== possibly lost: 0 bytes in 0 blocks.
==1375== still reachable: 20 bytes in 1 blocks.
==1375== suppressed: 0 bytes in 0 blocks.


Как мне убрать этот меморилик? или проще смирится?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.