riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
579 stars 306 forks source link

pk does not release file handles on an fclose #258

Closed MarkHillHuawei closed 2 years ago

MarkHillHuawei commented 2 years ago

This short program illustrates the problem: test00.c:

include

include

include

int main() { FILE *fd; int open_files=0; while (1){ fd = fopen("test00.c","r"); fclose(fd); if (fd) open_files++; else break; } printf("errno:%d\nopen:%d\n",errno,open_files); }

It should never terminate but fails after about 125 iterations (close to MAX_FILES value set in pk/file.c), the behaviour is the same as when "fclose" is commented out.

aswaterman commented 2 years ago

Thanks for providing a test case, @MarkHillHuawei. Fixed.

MarkHillHuawei commented 2 years ago

And thank you for the speedy fix!