[libc-commits] [libc] [libc] Implement freopen (PR #207837)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Fri Aug 7 00:29:05 PDT 2026


================
@@ -309,4 +311,16 @@ int reopenfile(File *f, const char *path, const char *mode) {
   return 0;
 }
 
+int reopenfile(File *f, const char *path, const char *mode) {
----------------
kaladron wrote:

We need to be careful of global static streams here.  Let's take:

```c++
freopen("/nonexistent", "r", stdout)
```

The f->close() will correctly go through per spec and close the existing stream.  However, this code also calls through to linux_file_close, which will call delete.  Since std* are not dynamically allocated, this is an invalid free.

https://github.com/llvm/llvm-project/pull/207837


More information about the libc-commits mailing list