fclose() is causing a segfault. I have :
char buffer[L_tmpnam];
char *pipeName = tmpnam(buffer);
FILE *pipeFD = fopen(pipeName, "w"); // open for writing
...
...
...
fclose(pipeFD);
I don’t do any file related stuff in the … yet so that doesn’t affect it. However, my MAIN process communicates with another process through shared memory where pipeName is stored; the other process fopen’s this pipe for reading to communicated with MAIN.
Any ideas why this is causing a segfault?
Thanks,
Hristo
Pass
pipeFDtofclose.fclosecloses the file by file handleFILE*not filenamechar*. With C (unlike C++) you can do implicit type conversions of pointer types (in this case char* to FILE*), so that’s where the bug comes from.Check if pepeFD is non NULL before calling
fclose.Edit: You confirmed that the error was due to fopen failing, you need to check the error like so:
Example output: