Pouvez-vous m'aider à résoudre mon memory leak ? - C - Programmation
Marsh Posté le 21-04-2005 à 19:21:19
Sans le code, on peut pas t'aider.
Marsh Posté le 21-04-2005 à 19:35:45
oué, mais bon il t'indique les fonctions causant des fuites et le lieu de l'allocation, avec ca tu devrais y arriver
Marsh Posté le 22-04-2005 à 09:40:46
Puisque c'est si gentillement demandé
Voici les parties du code qui pourraient poser problème :
Code :
|
EDIT : ajout des n° de ligne utiles
Marsh Posté le 22-04-2005 à 10:58:58
ha! sauf que tes numéros de lignes ne correspondent pas aux numéros de lignes de valgrind...
Par exemple:
==13224== 4 bytes in 1 blocks are still reachable in loss record 1 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x1B903EFB: realloc vg_replace_malloc.c:188)
==13224== by 0x80490E5: add (phpwrapperd.c:151)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==
C'est-à-dire que tu fais un alloc sans free à la ligne 151 du fichier phpwrapperd.c, dans la fonction add
Marsh Posté le 22-04-2005 à 11:44:05
J'ai mis les n° de lignes en commentaires aux endroits indiqués par valgrind
Marsh Posté le 21-04-2005 à 17:29:50
Bonjour,
Voilà, je viens de faire un prog en C, et le problème, c'est que la mémoire qu'il utilise augmente sans arrêt. Alors j'ai lancé le programme avec valgrind, et voici ce qu'il me répond :
==13224== Memcheck, a memory error detector for x86-linux.
==13224== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==13224== Using valgrind-2.4.0, a program supervision framework for x86-linux.
==13224== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==13224== For more details, rerun with: -v
==13224==
==13224==
==13224== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 27 from 1)
==13224== malloc/free: in use at exit: 31465 bytes in 451 blocks.
==13224== malloc/free: 4120 allocs, 3669 frees, 3847254 bytes allocated.
==13224== For counts of detected errors, rerun with: -v
==13224== searching for pointers to 451 not-freed blocks.
==13224== checked 10924852 bytes.
==13224==
==13224== 4 bytes in 1 blocks are still reachable in loss record 1 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x1B903EFB: realloc (vg_replace_malloc.c:188)
==13224== by 0x80490E5: add (phpwrapperd.c:151)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 10 bytes in 2 blocks are still reachable in loss record 2 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049938: get_user (phpwrapperd.c:338)
==13224== by 0x8049B77: send_phpconfig (phpwrapperd.c:379)
==13224== by 0x804A08D: main (phpwrapperd.c:555)
==13224==
==13224==
==13224== 16 bytes in 1 blocks are still reachable in loss record 3 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8048FFE: add (phpwrapperd.c:131)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 16 bytes in 1 blocks are still reachable in loss record 4 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049034: add (phpwrapperd.c:137)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 20 bytes in 2 blocks are still reachable in loss record 5 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x80499D9: get_user (phpwrapperd.c:346)
==13224== by 0x8049B77: send_phpconfig (phpwrapperd.c:379)
==13224== by 0x804A08D: main (phpwrapperd.c:555)
==13224==
==13224==
==13224== 20 bytes in 2 blocks are still reachable in loss record 6 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049077: add (phpwrapperd.c:142)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 28 bytes in 1 blocks are still reachable in loss record 7 of 19
==13224== at 0x1B903F72: realloc (vg_replace_malloc.c:196)
==13224== by 0x80490E5: add (phpwrapperd.c:151)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 48 bytes in 2 blocks are still reachable in loss record 8 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049825: get_user (phpwrapperd.c:315)
==13224== by 0x8049B77: send_phpconfig (phpwrapperd.c:379)
==13224== by 0x804A08D: main (phpwrapperd.c:555)
==13224==
==13224==
==13224== 60 bytes in 2 blocks are still reachable in loss record 9 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049A5C: get_user (phpwrapperd.c:351)
==13224== by 0x8049B77: send_phpconfig (phpwrapperd.c:379)
==13224== by 0x804A08D: main (phpwrapperd.c:555)
==13224==
==13224==
==13224== 68 bytes in 1 blocks are possibly lost in loss record 10 of 19
==13224== at 0x1B903E89: calloc (vg_replace_malloc.c:175)
==13224== by 0x1B8F2C2B: _dl_allocate_tls (in /lib/ld-2.3.2.so)
==13224== by 0x1B9E126D: allocate_stack (in /lib/tls/libpthread-0.60.so)
==13224== by 0x1B9E0EF7: pthread_create@@GLIBC_2.1 (in /lib/tls/libpthread-0.60.so)
==13224== by 0x8049EB8: main (phpwrapperd.c:499)
==13224==
==13224==
==13224== 96 bytes in 14 blocks are still reachable in loss record 11 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x804A213: init_config (config.c:51)
==13224== by 0x8049E3D: main (phpwrapperd.c:462)
==13224==
==13224==
==13224== 168 bytes in 14 blocks are still reachable in loss record 12 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x804A1C3: init_config (config.c:49)
==13224== by 0x8049E3D: main (phpwrapperd.c:462)
==13224==
==13224==
==13224== 187 bytes in 8 blocks are still reachable in loss record 13 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x804913F: add (phpwrapperd.c:154)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 192 bytes in 14 blocks are still reachable in loss record 14 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x804A1EA: init_config (config.c:50)
==13224== by 0x8049E3D: main (phpwrapperd.c:462)
==13224==
==13224==
==13224== 608 bytes in 76 blocks are indirectly lost in loss record 15 of 19
==13224== at 0x1B903F72: realloc (vg_replace_malloc.c:196)
==13224== by 0x80490E5: add (phpwrapperd.c:151)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 760 bytes in 76 blocks are indirectly lost in loss record 16 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8049077: add (phpwrapperd.c:142)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 3420 bytes in 152 blocks are indirectly lost in loss record 17 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x804913F: add (phpwrapperd.c:154)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 6004 (1216 direct, 4788 indirect) bytes in 76 blocks are definitely lost in loss record 18 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x8048FFE: add (phpwrapperd.c:131)
==13224== by 0x80493B4: reset_configs (phpwrapperd.c:203)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224==
==13224== 24528 bytes in 6 blocks are still reachable in loss record 19 of 19
==13224== at 0x1B90354C: malloc (vg_replace_malloc.c:130)
==13224== by 0x1B923EA2: my_once_alloc (in /usr/lib/mysql/libmysqlclient.so.14.0.0)
==13224== by 0x1B925244: init_state_maps (in /usr/lib/mysql/libmysqlclient.so.14.0.0)
==13224== by 0x1B92510C: get_charset_by_csname (in /usr/lib/mysql/libmysqlclient.so.14.0.0)
==13224== by 0x1B93564E: mysql_real_connect (in /usr/lib/mysql/libmysqlclient.so.14.0.0)
==13224== by 0x8049262: reset_configs (phpwrapperd.c:172)
==13224== by 0x804A047: main (phpwrapperd.c:537)
==13224==
==13224== LEAK SUMMARY:
==13224== definitely lost: 1216 bytes in 76 blocks.
==13224== indirectly lost: 4788 bytes in 304 blocks.
==13224== possibly lost: 68 bytes in 1 blocks.
==13224== still reachable: 25393 bytes in 70 blocks.
==13224== suppressed: 0 bytes in 0 blocks.
Il me dit bien qu'il y a des pertes de mémoire. Mais par où dois-je commencer pour résoudre ces erreurs ?
Merci