how to free the temporary pointer, one creates during the check function?

valgrind shows error on that particular statement

tried freeing it only when it has reached null, i.e., transverse over all the linked lists but that didn't work. also tried declaring the pointers as global nodes so as to, free them in unload function but that didn't sort it out.

thanks to anyone who gives their time.

  • keep in mind that valgrind often reports where the memory was created that leads to an error, not necessarily where the error is located. You should look carefully at the error message, the line described and any other line that uses the same pointer(s). This is especially true for memory leaks. What's the exact error message that you're getting?
    – Cliff B
    Apr 19 '20 at 3:35

if you create a pointer without reserving memory with alloc() you don't need to free It. If it's memory reserved in the load function you need to free it in the unload function using free(pointer to memory). Hard to know without seeing the code


i was actually, using malloc to create the temporary nodes, to traverse the linked lists. But, i eventually realized that, since the memory was already created, i did not need to use malloc, and hence not required to free it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .