rewrite popen to use posix_spawn instead of fragile vfork hacks
[musl] / src / stdio / fclose.c
index 373a2c7..38e8a1e 100644 (file)
@@ -3,9 +3,11 @@
 int fclose(FILE *f)
 {
        int r;
-       int perm = f->flags & F_PERM;
+       int perm;
+       
+       FFINALLOCK(f);
 
-       if (!perm) {
+       if (!(perm = f->flags & F_PERM)) {
                OFLLOCK();
                if (f->prev) f->prev->next = f->next;
                if (f->next) f->next->prev = f->prev;
@@ -16,6 +18,7 @@ int fclose(FILE *f)
        r = fflush(f);
        r |= f->close(f);
 
+       if (f->getln_buf) free(f->getln_buf);
        if (!perm) free(f);
        
        return r;