What happens if i open a file using fopen
some n number of times without calling fclose
on it?
Any buffer overrun issues may arise?
If you continue to fopen
without fclose
then eventually your future calls to fopen
will start to fail. There are a limited number of file descriptors available to your program.
See this related SO question.
You waste underlying file handles. Please close any files you open, in a timely fashion, as to avoid this leak of resources.
If you continue opening files without closing them then you will run out of file descriptors at some point, either at the application level or the OS level, and all further attempts to open a file will fail.
Aside from wasting file descriptors for the process as others answered, you would also waste memory since each file stream manages in/out buffers that are allocated internally by libc
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With