Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
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