views:

405

answers:

2

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?

A: 

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

Allan Wind
+4  A: 

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.

DGentry