I have a code like this
char *verboseBuf = NULL;
if(somethin){
for(a loop){
for(another loop){
if(somethin else){
if(curl execution){
if(fail){
verboseBuf = (char *) malloc(sizeof(char) * (currSize +1));
fread(verboseBuf, 1, currSize, verboseFd);
verboseBuf[currSize + 1] = '\0';
string verbose = verboseBuf;
free(verboseBuf);
}
}
}
}
}
}
The only place that i use the verboseBuf is inside the final if loop. but i get
*** glibc detected *** ./test: double free or corruption (!prev): 0x13c13290 ***
But how can be freeing it twice if i only use it in one place? and everytime i use it, i free it.
I tried using addr2line to find the place where it was freed previously but all got was a ??:0.
This line is writing one byte past the end of your buffer.