The *fp is a global variable, so each therad will initialize it with fopen and after finished working try to close it. the *fp is shared between threads (which should not be) so each thread before exiting tries to close the file handle stored in *fp and the double free occurs when multiple threads tries to close file handle which closed already by another thread.
You have to put *fp inside function block to make it local to each thread or add __thread before *fp declaration to make it local for each thread instance.
__thread FILE * fp;
0
solved Error while compiling the code ‘double free or corruption (out)’ using threads in C? [closed]