I am currently learning the C programming language, and I decided to implement several data structures in order to help learn the language. However, I am stuck because I am not sure what the proper process is of pointer ownership. For Instance, If an element is added to the list, should the list, when the destroy function is called" loop through the list and free the pointers to the data elements or just free the list nodes and let the user worry about the pointers to the elements because I am not sure if the pointers that were passed were allocated on the heap or the stack. Here is the code if it will help better explain my question: https://github.com/haglerchristopher/data-structures/blob/master/list/single_linkedlist/linkedlist.c#L35. Thanks in advance.
I found the correct solution to the problem. Upon creation of the linked list, I have the user pass in a function pointer to their custom free function that knows how to handle freeing the data. If the function pointer is null, I just delete the list nodes.