我正在尝试使用 C 中的线程,如果这是线程函数,我在释放指针时遇到了一些问题
void *executor_func(void *param) {
char *lineEx = (char *) malloc (1024);
size_t lenEx = 1024;
ssize_t readEx;
FILE * fpEx;
char* pchEx;
fpEx = fopen(file, "r");
if (fpEx == NULL) {
printf("ERROR: couldnt open file\n");
exit(0);
}
while ((readEx = getline(&lineEx, &lenEx, fpEx)) != -1) {
pchEx = strtok(lineEx, " ");
//DO MY STUFF WITH THE LINE I RECEIVE FROM FILE
}
free(lineEx);
fclose(fpEx);
return NULL;
}
想象一下,我执行 executor_func() 的多个线程... free(lineEX) 在 Valgrind 给我带来了问题... 为什么会这样?