Bonjour
Voici mon problème. Je développe avec gcc v4.1.2 sous CentOS.
J'écris la fonction suivante:
Evidemment, je veux écrire un fichier log. Par contre, si j'ajoute à la fin de ma fonction un free(out), mon programme échoue à cette ligne avec la sortie suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 void writeLog(char *message){ int length = 23; char outstr[length]; time_t t; struct tm *tmp; char* out; FILE *log = fopen(logfile, "a+"); out = (char *)malloc(sizeof(char)*(strlen(outstr)+strlen(message))); checkPointer(out, "Null pointer", 6); t = time(NULL); tmp = localtime(&t); checkPointer(tmp, "Can not initialise time", 7); if (strftime(outstr, sizeof (outstr), "%Y-%m-%d %X ", tmp) == 0) { raise_error("Unable to set time", 8); } out = strcat(outstr, message); checkPointer(out, "Null pointer", 6); fprintf(log, "%s\n", out); fflush(log); fclose(log); }
Pourquoi un free provoquerait une telle erreur ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 *** glibc detected *** /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment: double free or corruption (out): 0xbfbf4810 *** ======= Backtrace: ========= /lib/libc.so.6[0xa440f1] /lib/libc.so.6(cfree+0x90)[0xa47bc0] /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment[0x80488c7] /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment[0x804898f] /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment[0x80489bc] /lib/libc.so.6(__libc_start_main+0xdc)[0x9f0e8c] /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment[0x8048591] ======= Memory map: ======== 001a1000-001ac000 r-xp 00000000 fd:04 3178735 /lib/libgcc_s-4.1.2-20080825.so.1 001ac000-001ad000 rwxp 0000a000 fd:04 3178735 /lib/libgcc_s-4.1.2-20080825.so.1 00873000-0087a000 r-xp 00000000 fd:04 3179312 /lib/librt-2.5.so 0087a000-0087b000 r-xp 00006000 fd:04 3179312 /lib/librt-2.5.so 0087b000-0087c000 rwxp 00007000 fd:04 3179312 /lib/librt-2.5.so 009bd000-009d7000 r-xp 00000000 fd:04 3178685 /lib/ld-2.5.so 009d7000-009d8000 r-xp 00019000 fd:04 3178685 /lib/ld-2.5.so 009d8000-009d9000 rwxp 0001a000 fd:04 3178685 /lib/ld-2.5.so 009db000-00b19000 r-xp 00000000 fd:04 3178711 /lib/libc-2.5.so 00b19000-00b1b000 r-xp 0013e000 fd:04 3178711 /lib/libc-2.5.so 00b1b000-00b1c000 rwxp 00140000 fd:04 3178711 /lib/libc-2.5.so 00b1c000-00b1f000 rwxp 00b1c000 00:00 0 00b4a000-00b4c000 r-xp 00000000 fd:04 3178729 /lib/libdl-2.5.so 00b4c000-00b4d000 r-xp 00001000 fd:04 3178729 /lib/libdl-2.5.so 00b4d000-00b4e000 rwxp 00002000 fd:04 3178729 /lib/libdl-2.5.so 00b7b000-00b7c000 r-xp 00b7b000 00:00 0 [vdso] 00c8f000-00ca2000 r-xp 00000000 fd:04 3179150 /lib/libpthread-2.5.so 00ca2000-00ca3000 r-xp 00012000 fd:04 3179150 /lib/libpthread-2.5.so 00ca3000-00ca4000 rwxp 00013000 fd:04 3179150 /lib/libpthread-2.5.so 00ca4000-00ca6000 rwxp 00ca4000 00:00 0 00d21000-00d24000 r-xp 00000000 fd:04 42274988 /home/dbourgais/netbeans-6.7/dlight1/tools/Linux-x86/bin/prof_agent.so 00d24000-00d25000 r-xp 00002000 fd:04 42274988 /home/dbourgais/netbeans-6.7/dlight1/tools/Linux-x86/bin/prof_agent.so 00d25000-00d26000 rwxp 00003000 fd:04 42274988 /home/dbourgais/netbeans-6.7/dlight1/tools/Linux-x86/bin/prof_agent.so 00f3d000-00f3e000 r-xp 00000000 fd:04 42274976 /home/dbourgais/netbeans-6.7/dlight1/bin/nativeexecution/Linux-x86/unbuffer.so 00f3e000-00f3f000 rwxp 00000000 fd:04 42274976 /home/dbourgais/netbeans-6.7/dlight1/bin/nativeexecution/Linux-x86/unbuffer.so 08048000-08049000 r-xp 00000000 fd:04 45581947 /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment 08049000-0804a000 rw-p 00000000 fd:04 45581947 /home/dbourgais/Projects/Streptomics/GenomeAssembling/mpa/dist/make_pairwise_alignment 08505000-08526000 rw-p 08505000 00:00 0 [heap] b7e00000-b7e21000 rw-p b7e00000 00:00 0 b7e21000-b7f00000 ---p b7e21000 00:00 0 b7f23000-b7f25000 rw-p b7f23000 00:00 0 b7f3e000-b7f3f000 rw-p b7f3e000 00:00 0 bfbe1000-bfbf6000 rw-p bffea000 00:00 0 [stack] RUN FAILED (exit value 134, total time: 592ms)
Merci d'avance de votre aide.
@++
Partager