I don't know why this warning occurs I tried to write a code to delete the repeated data in the linked list and the point that I realized is that when I comment the line which contains free command the warning won't happen! and I got this warning in the visual studio 2019 compiler please tell me what is it for and how can I fix this problem
#include <stdio.h>
#include <stdlib.h>
typedef struct list List;
struct list
{
int data;
List* next;
};
List* remove_repetition(List* list)
{
List* pre = list;
if (pre == NULL)
return NULL;
List* now = list->next;
while (now != NULL)
{
if (pre->data == now->data)//the warning occurs here!
{
pre->next = now->next;
List* del = now;
now = now->next;
free(del);
}
else
{
pre = now;
now = now->next;
}
}
return list;
}
void out(List* head)
{
List* now = head;
while (now != NULL)
{
printf("%d\t", now->data);
now = now->next;
}
return;
}
int main() {
int i;
List* head1 = (List*)malloc(sizeof(List));
if (head1 == NULL)
exit(1);
List* head_temp = head1;
int data[8] = { 1,1,1,1,5,5,5,10 };
for (i = 0; i < 7; i++) {
head_temp->data = data[i];
List* next = (List*)malloc(sizeof(List));
if (next == NULL)
exit(1);
head_temp->next = next;
head_temp = next;
}
head_temp->data = data[i];
head_temp->next = NULL;
out(remove_repetition(head1));
}