diff --git a/libc/runtime/zipos-close.c b/libc/runtime/zipos-close.c index c6559016a..3c0ba3982 100644 --- a/libc/runtime/zipos-close.c +++ b/libc/runtime/zipos-close.c @@ -39,7 +39,7 @@ int __zipos_close(int fd) { if (!__vforked) { struct ZiposHandle *h; h = (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle; - __zipos_free(h); + __zipos_drop(h); } return rc; } diff --git a/libc/runtime/zipos-open.c b/libc/runtime/zipos-open.c index 9a9ebcb67..da92c9d37 100644 --- a/libc/runtime/zipos-open.c +++ b/libc/runtime/zipos-open.c @@ -88,18 +88,11 @@ struct ZiposHandle *__zipos_keep(struct ZiposHandle *h) { return h; } -static bool __zipos_drop(struct ZiposHandle *h) { - if (!atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release)) { - atomic_thread_fence(memory_order_acquire); - return true; - } - return false; -} - -void __zipos_free(struct ZiposHandle *h) { - if (!__zipos_drop(h)) { +void __zipos_drop(struct ZiposHandle *h) { + if (atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release)) { return; } + atomic_thread_fence(memory_order_acquire); if (IsAsan()) { __asan_poison((char *)h + sizeof(struct ZiposHandle), h->mapsize - sizeof(struct ZiposHandle), kAsanHeapFree); @@ -227,7 +220,7 @@ static int __zipos_load(struct Zipos *zipos, size_t cf, int flags, } __fds_unlock(); } - __zipos_free(h); + __zipos_drop(h); return -1; } @@ -238,7 +231,7 @@ void __zipos_postdup(int oldfd, int newfd) { BLOCK_SIGNALS; __fds_lock(); if (__isfdkind(newfd, kFdZip)) { - __zipos_free((struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle); + __zipos_drop((struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle); if (!__isfdkind(oldfd, kFdZip)) { bzero(g_fds.p + newfd, sizeof(*g_fds.p)); } diff --git a/libc/runtime/zipos.S b/libc/runtime/zipos.S index 0129793dd..507db9efe 100644 --- a/libc/runtime/zipos.S +++ b/libc/runtime/zipos.S @@ -35,7 +35,7 @@ .yoink __zipos_mmap .yoink __zipos_postdup .yoink __zipos_keep - .yoink __zipos_free + .yoink __zipos_drop // TODO(jart): why does corruption happen when zip has no assets? .yoink .cosmo diff --git a/libc/runtime/zipos.internal.h b/libc/runtime/zipos.internal.h index 30fbf9adc..b7549fc9f 100644 --- a/libc/runtime/zipos.internal.h +++ b/libc/runtime/zipos.internal.h @@ -38,7 +38,7 @@ struct Zipos { }; int __zipos_close(int); -void __zipos_free(struct ZiposHandle *); +void __zipos_drop(struct ZiposHandle *); struct ZiposHandle *__zipos_keep(struct ZiposHandle *); struct Zipos *__zipos_get(void) pureconst; size_t __zipos_normpath(char *, const char *, size_t);