I made a smaller scenario of my bigger problem. What I try to do is pass a string to a function which will make a new string out of it. However I ran into some problems.
You are using buff
without initializing it. Try:
char buff[1024];
buff[0] = 0;
Something else I find weird is that I can printf the value of newStr just after I have freed it.
Accessing memory after freeing it is undefined behavior. Typically, for performance reasons, free
doesn't zero the memory.
That's 2 cases of undefined behavior in the same question + one really weird typedef
. Keep it up!