Hacker News new | ask | show | jobs
by jamesdsadler 2023 days ago
Both of these implementations seem to be missing a call to `free`, or is that something that the caller should be taking care of?
5 comments

The caller could want to move the element from one list to another, in which case the optimum impl would not free or copy the element.
It's pseudocode. The code as-is is not valid C anyway.
Now you are assuming "remove_list_entry" is not a macro!
As others have said, often you don't want to free the node, you want to do something else with it. E.g., put it in a free list. However, usually if you're not freeing it, you'd null out the next field so that you don't accidentally access it when it's not part of the list (at least I would).
Depends on whether the list owns the nodes. I tend to write mine such that it does. Perhaps this code is demonstrative rather than complete.
Why do you think the values were allocated in the heap?