0
내 함수 remove_duplicates는 연결된 목록에서 중복 데이터 값을 제거해야합니다. 그러나 링크 된 목록의 한 지점에 도달하면 예를 들어 연결된 목록이 L = {10,10,20,30,30,30,40,50}
인 경우 L = {10,20,30,40,50}
일 때 출력은 L = {10,20,30,(some random int value like 23687328),50}
입니다. 또한 누출 여부를 확인 중이며 Valgrind는 내가 어딘가에 새고 있다고 말하고 있지만 찾을 수는 없습니다. 내가 Valgrind의 --leak 검사를 사용하고링크 된 목록에서 중복을 해제하고 삭제 하시겠습니까?
typedef struct node_t
{
int data;
struct node_t *next;
} node;
void remove_duplicates(node * head)
{
node* temp;
while (head != NULL && head->next != NULL)
{
while (head->data == head->next->data)
{
temp = head->next->next;
free(head->next);
head->next = temp;
}
head = head->next;
}
free(temp);
}
= 예 ./llistprac 및 출력은
==24802== 80 (16 direct, 64 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==24802== at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==24802== by 0x400575: append (in /home/llistprac)
==24802== by 0x4006D9: main (in /home/llistprac)
==24802==
==24802== LEAK SUMMARY:
==24802== definitely lost: 16 bytes in 1 blocks
==24802== indirectly lost: 64 bytes in 4 blocks
==24802== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
흥미롭게도 (적어도 나에게), 내가 끝까지 무료 임시 직원을 쓰지 않을 때, 그것은 효과적이다! 하지만 여전히 누출되고 있습니다. – Bourezg
Valgrind가 누출이라고 말하면서 찾을 수는 없지만, 어떤 주장을 사용하고 Valgrind 출력은 무엇입니까? – kbshimmyo
임시 직원을 풀 필요가 없습니다. – Duck