Bonjour,

Le code concerné vient d'un exemple de Dr Dobbs (de 1995, ça nous rajeunit pas) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
    if (colorTable != NULL)
	free(colorTable);
Au début de la proc :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
    RGB              *colorTable;
    colorTable = (RGB *)calloc(numColors, sizeof(RGB));
Dans un .h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
/*
 * RGB defines a single color palette entry.  Its analogues in the Windows SDK
 * are the RGBTRIPLE and RGBQUAD structures.  Its analogues in the OS/2
 * Toolkit are the RGB and RGB2 structure. 
 */
typedef struct RGB
{
    UINT8 blue;
    UINT8 green;
    UINT8 red;
} RGB;
Si je remplace la ligne free(colorTable); par printf("Hello, World!\n"); je vois bien le message --> j'en conclus que colorTable est bien différent de NULL, alors pourquoi tant de haine et de violence à l'exécution du code d'origine ?
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
*** glibc detected *** ./testBMP.exe: free(): invalid pointer: 0xb77bdff4 ***
======= Backtrace: =========
/lib/i386-linux-gnu/i686/cmov/libc.so.6(+0x70c91)[0xb76cdc91]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(+0x724f8)[0xb76cf4f8]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(cfree+0x6d)[0xb76d263d]
./testBMP.exe[0x804ab1a]
./testBMP.exe[0x8048a7e]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7673e46]
./testBMP.exe[0x80486a1]
======= Memory map: ========
08048000-0804c000 r-xp 00000000 08:02 926278     /chemin/Dr_Dobbs/prog/testBMP.exe
0804c000-0804d000 rw-p 00003000 08:02 926278     /chemin/Dr_Dobbs/prog/testBMP.exe
09c6d000-09c8e000 rw-p 00000000 00:00 0          [heap]
b7500000-b7521000 rw-p 00000000 00:00 0 
b7521000-b7600000 ---p 00000000 00:00 0 
b7624000-b7640000 r-xp 00000000 08:02 4325509    /lib/i386-linux-gnu/libgcc_s.so.1
b7640000-b7641000 rw-p 0001b000 08:02 4325509    /lib/i386-linux-gnu/libgcc_s.so.1
b765c000-b765d000 rw-p 00000000 00:00 0 
b765d000-b77bc000 r-xp 00000000 08:02 4325472    /lib/i386-linux-gnu/i686/cmov/libc-2.13.so
b77bc000-b77be000 r--p 0015e000 08:02 4325472    /lib/i386-linux-gnu/i686/cmov/libc-2.13.so
b77be000-b77bf000 rw-p 00160000 08:02 4325472    /lib/i386-linux-gnu/i686/cmov/libc-2.13.so
b77bf000-b77c2000 rw-p 00000000 00:00 0 
b77db000-b77df000 rw-p 00000000 00:00 0 
b77df000-b77e0000 r-xp 00000000 00:00 0          [vdso]
b77e0000-b77fc000 r-xp 00000000 08:02 4330281    /lib/i386-linux-gnu/ld-2.13.so
b77fc000-b77fd000 r--p 0001b000 08:02 4330281    /lib/i386-linux-gnu/ld-2.13.so
b77fd000-b77fe000 rw-p 0001c000 08:02 4330281    /lib/i386-linux-gnu/ld-2.13.so
bfa6f000-bfa90000 rw-p 00000000 00:00 0          [stack]
Abandon
J'ai lu et relu le tuto, la seule différence avec mon cas c'est qu'il s'agit d'une structure de 3 UINT8 : ça change beaucoup de choses ?

Je me suis paluché le man malloc :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
void *calloc(size_t nmemb, size_t size);
 
  The calloc() function allocates memory for an array of nmemb elements of size bytes each 
  and returns a pointer to the allocated memory. The memory is set to zero. 
  If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value 
  that can later be successfully passed to free().
Quelqu'un peut m'aider à dépatouiller ça ?
Merci et bon dimanche,