Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an fdopen() cause a memory leak?

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

like image 218
Adam Davis Avatar asked Sep 06 '25 13:09

Adam Davis


1 Answers

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.

like image 178
DGentry Avatar answered Sep 11 '25 03:09

DGentry