Linked List memory leak
So, I'm implementing mergesort using Nodes and Linked Lists. Running my program through valgrind, all of my leaks originate from my merge function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
LList<int>::Node* merge(LList<int>::Node *a, LList<int>::Node *b)
{
LList<int>::Node* endlist=NULL;
if(a==NULL)return b;
if(b==NULL)return a;
if(a->value <= b->value)
{
endlist=a;
endlist->next=merge(a->next,b);
}
else
{
endlist=b;
endlist->next=merge(a,b->next);
}
return endlist;
}
| |
Where is this memory leak occuring? Valgrind points to everywhere merge is called
I don't see any leaks here.
Perhaps it's in the code that is calling merge and not in merge itself?
Topic archived. No new replies allowed.