From c860be3de7e742b42a0927b1d97454fc1beeba33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Wed, 3 Apr 2024 14:29:07 -0400 Subject: [PATCH] Move store after __asan_unpoison in __zipos_alloc Previously, the atomic store looked like it was happening while the struct's memory was still poisoned. I was unable to observe any issues with this, but this change seems to make the code more obviously correct (at the cost of a redundant atomic store to zeroed space in case the map needed to be extended.) --- libc/runtime/zipos-open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/runtime/zipos-open.c b/libc/runtime/zipos-open.c index 83b71ed76..d3bb03555 100644 --- a/libc/runtime/zipos-open.c +++ b/libc/runtime/zipos-open.c @@ -114,7 +114,6 @@ StartOver: while ((h = *ph)) { if (h->mapsize >= mapsize) { if (!_cmpxchg(ph, h, h->next)) goto StartOver; - atomic_store_explicit(&h->refs, 0, memory_order_relaxed); break; } ph = &h->next; @@ -130,6 +129,7 @@ StartOver: kAsanHeapOverrun); } if (h) { + atomic_store_explicit(&h->refs, 0, memory_order_relaxed); h->size = size; h->zipos = zipos; h->mapsize = mapsize;