У меня есть следующие struct
:Нужно ли мне освобождать локальные переменные?
typedef struct cell Cell;
struct cell {
int value;
int *nextcell;
};
И у меня есть следующие функции, чтобы освободить связанный список:
void freelist(Cell *beginning)
{
Cell *thisCell = beginning;
Cell *NextCell = beginning->nextcell;
while (thisCell != NULL)
{
NextCell = thisCell->nextcell;
free(thisCell);
thisCell = NextCell;
}
/* Here comes my question. Do I need to free the following variables? */
free(beginnig);
free(thisCell);
free(NextCell);
}
Вы не являетесь свободными переменными, вы освобождаете память. Правило большого пальца: один свободный на malloc (или realloc). –