im trying to free this linked list but for some reason visual studio memory usage always shows me that 5 or 6 extra allocations stay with each iteration of the program.
this is the function i use to create the linked list :
int index = 0, c = 0, nodes_count = 0, d = info.height, maxtempx = -1, firstscan = 1, maxtempy = -1, mintempx = 502, mintempy = 502;
chargers_list_t* head = NULL;
chargers_list_t* temp = malloc(sizeof(chargers_list_t));
if (temp == NULL)
{
printf_s("error creating list\n");
return NULL;
}
for (int i = info.height - 1; i >= 0; i--) {
for (int j = 0; j < info.width; j++) {
if (matrix[i][j] == -1) {
index++;
group_chargers(matrix, i, j, index, info);
chargers_list_t* temp = malloc(sizeof(chargers_list_t));
if (temp == NULL) {
printf_s("error allocation\n");
return NULL;
}
temp->index = index;
temp->next = NULL;
if (head == NULL)
head = temp;
else {
chargers_list_t* tail = head;
while (tail->next != NULL) {
tail = tail->next;
}
tail->next = temp;
}
}
}
}
and this is the function i use to free it:
oid freeList(chargers_list_t* head) {
if (head == NULL) {
return;
}
freeList(head->next);
free(head);
}
i tried freeing it both in a while loop and recursively but the result stays the same