Hello,
I am a C beginner, and I am writing a very simple linked-list. I am wondering if there would be a memory leak in the following code:
void removeListEntry(struct tableEntry *symp, struct tableEntry *previous) {
if (symp->next = 0){
symbolList.tail = previous;
previous->next =0;
} else {
previous->next = symp->next;
symp->next = 0;
}
}
I am pretty sure if the pointer symp is not stored in another variable, there's no way of accessing the list entry that was pointed by the pointer, thus I will have a memory leak. In C, we use malloc() function to allocate memory space for a data structure, and I remember using new keyword to "dynamically" allocate memory in C++. What are the differences between allocating memory using malloc() and using new? Is there indeed a memory leak in my code?