Linux - Liberar memoria

 
Vista:

Liberar memoria

Publicado por cecilia (8 intervenciones) el 21/10/2007 00:23:05
Tengo una duda en cuando liberar memoria en lenguaje C, el codigo es el siguiente:


int suprimirNodo(struct nodo **Lista , int socket) {
struct nodo *ptrant,*ptr;
ptrant = NULL;
ptr = (*Lista);

if(ptr == NULL) {
printf("la lista esta vacia\n");
return -1;
}
while(ptr != NULL) {
if(ptr->socket != socket) {
ptrant = ptr;
ptr = ptr->sgte;
}
else {
if(ptrant != NULL) {
ptrant->sgte = ptr->sgte;
printf("se hace free del primero\n");
free(ptr);
}
else {
ptrant=ptr;
ptr = ptr->sgte;
printf("se hace free del segundo\n");
(*Lista)=ptr;
free(ptrant);

}
}/*FIN DEL ELSE DE "ptr->socket != socket"*/
}/*FIN DEL WHILE*/
return 0;
}/*FIN DE LA FUNCION*/

Cuando lo ejecuto me tira segmentation fault, alguien tiene alguna idea de porque puede ser?
Desde ya gracias me puedan ayudar.
Cecilia.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder