published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted in category Software Development & Programming / C & CPP
posted at 05. Dec '20
free(): invalid pointer in C
The error:
/home/project/src/str_replace.c:53:str_replace(): search_string, ' ORDER BY groups.id LIMIT 1
free(): invalid pointer
compile.sh: line 70: 40933 Aborted useradd john
Cause: trying to free the pointer which has been moved to a different position in a string
How to fix it: free at the beginning of a string, i.e. do pointer arithmetic back to the start of char* search_string
. Free from where memory allocated by malloc starts.
Add Comment