From 18abf7ca0a742fdd5e23e4fbacaaa5bbabe0f546 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 14 Jul 2022 03:50:30 +0800 Subject: [PATCH] fix ordering issue in refcount increment for trng want to add to the reference before claiming, so if a drop happens while we're claiming we don't get the connection being destroyed in the race. --- services/trng/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/trng/src/lib.rs b/services/trng/src/lib.rs index 9ae3d5575..d67638d96 100644 --- a/services/trng/src/lib.rs +++ b/services/trng/src/lib.rs @@ -12,10 +12,10 @@ pub struct Trng { } impl Trng { pub fn new(xns: &xous_names::XousNames) -> Result { + REFCOUNT.fetch_add(1, Ordering::Relaxed); let conn = xns .request_connection_blocking(api::SERVER_NAME_TRNG) .expect("Can't connect to TRNG server"); - REFCOUNT.fetch_add(1, Ordering::Relaxed); Ok(Trng { conn, error_sid: None,