gwenChina
Messages postés13Date d'inscriptionvendredi 29 avril 2005StatutMembreDernière intervention27 août 2005
-
4 juin 2005 à 05:01
gwenChina
Messages postés13Date d'inscriptionvendredi 29 avril 2005StatutMembreDernière intervention27 août 2005
-
8 juin 2005 à 06:11
Bonjour a tous,
Je viens de debuter mon stage, je suis donc nouveau dans ce forum.
En fait j'ai un probleme de liberation de memoire. J'alloue un pointeur avec malloc() mais losrque je fais mon free(), le compilateur me jette!!
Je me demandais si il y a vait des regles strictes a respecter pour la liberation de la memoire que je n'ai pas saisies.
En fait j'alloue la memoire qu'il faut, ensuite je place un pointeur (pointeur global au fichier C) qui va etre ensuite rempli par la fonction (readInHeader). Ensuite je compare tout ca avec un string mais lors de la desallocation, ca plante!!
Voici donc mon code:
static unsigned char CheckFileInformation()
{
// The file preamble is 128 bytes long
if ((SeekTheHeader(128,FROM_START)) == FAIL)
return FAIL;
// The prefix, situated just after the file preamble is read
// Memory allocation for the given length of bytes if ((pcAllocationPointer (unsigned char*)calloc(4,sizeof(unsigned char))) NULL)
{
// Cannot allocate the memory
gtErrorCode = ERROR_ALLOCATE_MEMORY;
free(pcAllocationPointer);
return FAIL;
}
// The pointer that will contain the reading value points in the
// memory allocation
pcReadingValues = pcAllocationPointer;
// Read in the header and fill the pcReadingValue pointer
if (ReadInHeader(4) == FAIL)
return FAIL;
// Adding of the null character for the string comparison
pcReadingValues[4] = 0;
if ((strcmp(pcReadingValues,aDicomPrefix)) != 0)
{
gtErrorCode = ERROR_PREFIX;
return FAIL;
}
free(pcAllocationPointer);// Ne veut pas desallouer le pointeur!!!
return SUCCESS;
}