From 3e16e59f7246dde78182753b7df0e49e38c1bcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Wed, 10 Apr 2024 23:04:03 -0400 Subject: [PATCH] Move store after __asan_unpoison in __zipos_alloc (#1135) 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;