IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

memory corruption error


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 28
    Par défaut memory corruption error
    Bonjour
    je suis desole de faire un enieme post sur un probleme d'allocation memoire mais la j'avoue que je seche et toute aide sera la biienvenue.

    Voila:
    j'ai un programme possédant une fonction qui appelle une autre fonction et ceci au sein d'une boucle de traitement:

    code de la fonction appelante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    int ** induct_graphs;
    for (...maboucle)
    {
    induct_graphs = heuristic(k, temp, decomp, decomp);
    result = test(induct_graphs);
    if (result == 0)
       return 0;
    }
    De façon résumé la fonction heuristic est la suivante:
    code de la fonction appelé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    int ** heuristic(...)
    {
    int ** graphs;
    ************************************
    graphs = calloc(1, sizeof(int*));
    alloc_test_2d_table(graphs); //test si le calloc de la matrice s'est bien déroulé
    graphs[0] = calloc(2, sizeof(int));
     
    ... traitement sur graphs ....
     
    return graphs;
    }
    Tout se passe bien pour un grand nombre de tour de boucle mais au bout d'un moment j'obtiens une erreur "memory corruption" (pas d'erreur ou de warning a la compil) ... au niveau des ************************************. c'est a dire que le calloc m'indique une erreur de corruption mémoire.
    Je ne comprends pas trop car il me semblait que la variable grph de ma fonction heuristic était libéré à la sortie de la fonction...

    Je ne vois pas ... si vous avez une idée je vous en remercie!!

  2. #2
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Juillet 2005
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juillet 2005
    Messages : 147
    Par défaut
    Salut,

    Si tu travailles sous linux, tu peux essayer d'exécuter ton programme avec l'outil Valgrind, qui te permettra d'avoir des infos sur la mémoire que tu utilises, que tu libères (ou pas ), et des erreurs d'allocation mémoire que tu pourrais faire. S'il indique des erreurs, et que tu ne vois pas trop la cause, envoie-nous le log, avec le code en archive si tu veux.
    Si tu n'es pas sous linux, je ne connais pas d'outils pour windows ou mac, mais ça doit exister, quelqu'un te renseignera surement.

    Bon courage

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 28
    Par défaut
    Merci pour ton aide, je vais essayé valgrind car je suis bien sous linux . Je vais egalemen faire d'autres essais mais franchement je comprends pas ce qui se passe...

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 28
    Par défaut
    Rahhh je viens de tester avec valgrind , le programme s'execute correctement lorsque j'utilise cet outil je vais aller voir le log... au cas ou je le met dessous mais je dois avouer que je ne comprends pas tout

    ==11366== Memcheck, a memory error detector.
    ==11366== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
    ==11366== Using LibVEX rev 1804, a library for dynamic binary translation.
    ==11366== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
    ==11366== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework.
    ==11366== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
    ==11366==
    ==11366== My PID = 11366, parent PID = 8876. Prog and args are:
    ==11366== ./main_RAVD
    ==11366==
    --11366--
    --11366-- Command line
    --11366-- ./main_RAVD
    --11366-- Startup, with flags:
    --11366-- -v
    --11366-- --tool=memcheck
    --11366-- --leak-check=full
    --11366-- --num-callers=40
    --11366-- --log-file=valgrind2.log
    --11366-- Contents of /proc/version:
    --11366-- Linux version 2.6.24-24-generic (buildd@palmer) (gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)) #1 SMP Tue Jul 7 19:46:39 UTC 2009
    --11366-- Arch and hwcaps: X86, x86-sse1-sse2
    --11366-- Page sizes: currently 4096, max supported 4096
    --11366-- Valgrind library directory: /usr/lib/valgrind
    --11366-- Reading syms from /lib/ld-2.7.so (0x4000000)
    --11366-- Reading debug info from /lib/ld-2.7.so...
    --11366-- ... CRC mismatch (computed aa5c1346 wanted 05177b25)
    --11366-- object doesn't have a symbol table
    --11366-- Reading syms from /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD (0x8048000)
    --11366-- Reading syms from /usr/lib/valgrind/x86-linux/memcheck (0x38000000)
    --11366-- object doesn't have a dynamic symbol table
    --11366-- Reading suppressions file: /usr/lib/valgrind/default.supp
    --11366-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_core.so (0x401E000)
    --11366-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so (0x4020000)
    --11366-- Reading syms from /lib/tls/i686/cmov/libc-2.7.so (0x4039000)
    --11366-- Reading debug info from /lib/tls/i686/cmov/libc-2.7.so...
    --11366-- ... CRC mismatch (computed af7c73db wanted ca2b0f8f)
    --11366-- object doesn't have a symbol table
    --11366-- REDIR: 0x40ab620 (rindex) redirected to 0x4023710 (rindex)
    --11366-- REDIR: 0x40ab250 (strlen) redirected to 0x40239d0 (strlen)
    --11366-- REDIR: 0x40ac510 (mempcpy) redirected to 0x4024490 (mempcpy)
    --11366-- REDIR: 0x40a6930 (calloc) redirected to 0x4021b70 (calloc)
    --11366-- REDIR: 0x40a8650 (realloc) redirected to 0x4022b10 (realloc)
    --11366-- REDIR: 0x40ad3a0 (strchrnul) redirected to 0x4023df0 (strchrnul)
    --11366-- REDIR: 0x40a6c20 (malloc) redirected to 0x4022a50 (malloc)
    --11366-- REDIR: 0x40a8460 (free) redirected to 0x40225f0 (free)
    --11366-- REDIR: 0x40ac9a0 (memcpy) redirected to 0x4024aa0 (memcpy)
    ==11366== Invalid write of size 4
    ==11366== at 0x804AE0B: test_graph_multipode (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B10B: test_ravd (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B616: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== Address 0x497cc5c is 0 bytes after a block of size 12 alloc'd
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x804B0AF: test_ravd (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B616: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    --11366-- REDIR: 0x40ac4b0 (memset) redirected to 0x4023d50 (memset)
    ==11366==
    ==11366== ERROR SUMMARY: 28 errors from 1 contexts (suppressed: 11 from 1)
    ==11366==
    ==11366== 28 errors in context 1 of 1:
    ==11366== Invalid write of size 4
    ==11366== at 0x804AE0B: test_graph_multipode (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B10B: test_ravd (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B616: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== Address 0x497cc5c is 0 bytes after a block of size 12 alloc'd
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x804B0AF: test_ravd (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B616: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    --11366--
    --11366-- supp: 11 dl-hack3-1
    ==11366==
    ==11366== IN SUMMARY: 28 errors from 1 contexts (suppressed: 11 from 1)
    ==11366==
    ==11366== malloc/free: in use at exit: 199,424 bytes in 10,841 blocks.
    ==11366== malloc/free: 187,781 allocs, 176,940 frees, 14,535,944 bytes allocated.
    ==11366==
    ==11366== searching for pointers to 10,841 not-freed blocks.
    ==11366== checked 64,692 bytes.
    ==11366==
    ==11366==
    ==11366== 16 bytes in 1 blocks are definitely lost in loss record 4 of 14
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x8048C6D: k_ballon_test_properties (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B2B5: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 16 bytes in 1 blocks are definitely lost in loss record 5 of 14
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x804B25C: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 16 bytes in 1 blocks are definitely lost in loss record 6 of 14
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x804B246: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 204 bytes in 2 blocks are definitely lost in loss record 7 of 14
    ==11366== at 0x4022B8E: realloc (vg_replace_malloc.c:429)
    ==11366== by 0x80486E4: reallocate_table (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x8048A6F: decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BB09: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 1,668 bytes in 144 blocks are definitely lost in loss record 9 of 14
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x804B0AF: test_ravd (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B616: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 12,132 bytes in 1,011 blocks are definitely lost in loss record 12 of 14
    ==11366== at 0x4021BDE: calloc (vg_replace_malloc.c:397)
    ==11366== by 0x8048796: reallocate_matrix (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x8049F9A: heuristic_3 (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B5FC: test_k_ballons_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804BBA9: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366==
    ==11366== 184,668 (33,908 direct, 150,760 indirect) bytes in 1,202 blocks are definitely lost in loss record 14 of 14
    ==11366== at 0x4022B8E: realloc (vg_replace_malloc.c:429)
    ==11366== by 0x804873E: reallocate_matrix (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x80488AA: copy_table (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804896C: sum_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x80489DC: sum_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x80489DC: sum_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x80489DC: sum_decomposition (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366== by 0x804B9ED: main (in /home/cha/Bureau/src/programmes_C/RAVD/main_RAVD)
    ==11366==
    ==11366== LEAK SUMMARY:
    ==11366== definitely lost: 47,960 bytes in 2,362 blocks.
    ==11366== indirectly lost: 150,760 bytes in 8,477 blocks.
    ==11366== possibly lost: 0 bytes in 0 blocks.
    ==11366== still reachable: 704 bytes in 2 blocks.
    ==11366== suppressed: 0 bytes in 0 blocks.
    ==11366== Reachable blocks (those to which a pointer was found) are not shown.
    ==11366== To see them, rerun with: --leak-check=full --show-reachable=yes
    --11366-- memcheck: sanity checks: 197 cheap, 9 expensive
    --11366-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
    --11366-- memcheck: auxmaps_L1: 0 searches, 0 cmps, ratio 0:10
    --11366-- memcheck: auxmaps_L2: 0 searches, 0 nodes
    --11366-- memcheck: SMs: n_issued = 144 (2304k, 2M)
    --11366-- memcheck: SMs: n_deissued = 0 (0k, 0M)
    --11366-- memcheck: SMs: max_noaccess = 65535 (1048560k, 1023M)
    --11366-- memcheck: SMs: max_undefined = 0 (0k, 0M)
    --11366-- memcheck: SMs: max_defined = 21 (336k, 0M)
    --11366-- memcheck: SMs: max_non_DSM = 144 (2304k, 2M)
    --11366-- memcheck: max sec V bit nodes: 0 (0k, 0M)
    --11366-- memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)
    --11366-- memcheck: max shadow mem size: 2608k, 2M
    --11366-- translate: fast SP updates identified: 2,543 ( 89.1%)
    --11366-- translate: generic_known SP updates identified: 168 ( 5.8%)
    --11366-- translate: generic_unknown SP updates identified: 141 ( 4.9%)
    --11366-- tt/tc: 5,498 tt lookups requiring 5,587 probes
    --11366-- tt/tc: 5,498 fast-cache updates, 2 flushes
    --11366-- transtab: new 2,730 (60,436 -> 839,921; ratio 138:10) [0 scs]
    --11366-- transtab: dumped 0 (0 -> ??)
    --11366-- transtab: discarded 0 (0 -> ??)
    --11366-- scheduler: 19,736,548 jumps (bb entries).
    --11366-- scheduler: 197/243,551 major/minor sched events.
    --11366-- sanity: 198 cheap, 9 expensive checks.
    --11366-- exectx: 769 lists, 100 contexts (avg 0 per list)
    --11366-- exectx: 195,404 searches, 195,308 full compares (999 per 1000)
    --11366-- exectx: 44,234 cmp2, 53 cmp4, 0 cmpAll
    --11366-- errormgr: 21 supplist searches, 1,125 comparisons during search
    --11366-- errormgr: 39 errlist searches, 59 comparisons during search

  5. #5
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Juillet 2005
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juillet 2005
    Messages : 147
    Par défaut
    Salut,

    Valgrind te signale bien des erreurs, et des fuites de mémoires. Je te conseille d'essayer de corriger d'abord les erreurs, tu as la ligne de la fonction qui les provoque, et c'est souvent un mauvais accès à la mémoire (dépassement de buffer, libération de pointeur non valide, etc). Une fois qu'il n'y a plus d'erreur, tu pourras corriger les memory leaks.

    Si tu ne trouves pas, postes ton code et je regarderai.

    @+

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 115
    Par défaut
    Je ne comprends pas trop car il me semblait que la variable grph de ma fonction heuristic était libéré à la sortie de la fonction...
    la variable oui mais pas la mémoire allouée dynamiquement

    d'ailleurs :

    ==11366== LEAK SUMMARY:
    ==11366== definitely lost: 47,960 bytes in 2,362 blocks.
    ==11366== indirectly lost: 150,760 bytes in 8,477 blocks.

  7. #7
    Membre émérite
    Inscrit en
    Juillet 2005
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 512
    Par défaut
    Dans la fonction heuristic de la memoire est alloué sur le tas,
    mais quand libère tu cette mémoire ?

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 28
    Par défaut
    Bonjour,
    je vous remercie pour vos reponse ...
    En fait je fais un:

    dans la fonction appellante (la fonction qui appelle heuristic).
    il me semblait que cela permettait de liberer la memoire d'induct_graph et donc de graph (memoire ayant été alloué dans heuristic).

    je ne vois pas comment libérer cette espace alloué puisque je renvoit ma matrice graph je ne peux libérer la mémoire qu'au niveau de la fonction appellante. (meme avec free , cela ne marche pas ).

    Merci en tout cas pour votre aide, je continue de chercher mais j'apprecie votre disponibilité.

Discussions similaires

  1. Réponses: 1
    Dernier message: 14/06/2009, 00h10
  2. [C] Malloc, memory Corruption
    Par publicStaticVoidMain dans le forum C
    Réponses: 2
    Dernier message: 18/05/2009, 01h39
  3. Réponses: 0
    Dernier message: 18/09/2007, 19h07
  4. memory corruption
    Par GLSpirit dans le forum C++
    Réponses: 2
    Dernier message: 23/05/2007, 08h42
  5. Réponses: 2
    Dernier message: 13/02/2007, 12h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo