c-linked-list | quick list
kandi X-RAY | c-linked-list Summary
kandi X-RAY | c-linked-list Summary
To compile: make To run: ./list To check for memory leaks (this will attempt to run with valgrind): make leaks.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of c-linked-list
c-linked-list Key Features
c-linked-list Examples and Code Snippets
Community Discussions
Trending Discussions on c-linked-list
QUESTION
why does function list_destroy, free current->data twice if its a string, (since freeing twice leads to an error), but this doesnt. list->freeFn calls a function that is a free type casted to char*, but then free(current->data) is called again without a type cast, so does this one not work ?
why do we have to type cast free for strings (char*) but not int, would of assumed to do it to all types?
original tutorial: https://pseudomuto.com/2013/05/implementing-a-generic-linked-list-in-c/
...ANSWER
Answered 2020-Jan-21 at 16:21The result of freeFn(current->data)
is free(*(char **)data)
which is different from free(current->data)
; although is dubious. Note that the difference comes from dereferencing the data (¤t->data) argument.
The tutorial is wrong, since the member data is not allocated. A possible fix would be to change:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install c-linked-list
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page