Question

I use fdopen to associate a stream with an open file.

When I close() the file, is the stream automatically disassociated as well, and all stream memory returned to the OS, or do I need to be aware of the fdopen'd file and close it in a specific manner?

-Adam

Was it helpful?

Solution

close() is a system call. It will close the file descriptor in the kernel, but will not free the FILE pointer and resources in libc. You should use fclose() on the FILE pointer instead, which will also take care of closing the file descriptor.

OTHER TIPS

The kernel manages those resources, and you have no control over them other than the close call which may free up the memory when it wants (no later than process termination).

/Allan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top