From 0e1dc9791eda1a46b2a7ad0380ab6c2a67f8d0c8 Mon Sep 17 00:00:00 2001 From: Adam Spofford <93943719+adamspofford-dfinity@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:06:55 -0700 Subject: [PATCH] fix: Fix memory leak in CallFuture (#509) --- src/ic-cdk/src/api/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ic-cdk/src/api/call.rs b/src/ic-cdk/src/api/call.rs index f95aa0231..e9827b574 100644 --- a/src/ic-cdk/src/api/call.rs +++ b/src/ic-cdk/src/api/call.rs @@ -72,7 +72,6 @@ impl> Future for CallFuture { fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll { let self_ref = Pin::into_inner(self); - let state_ptr = Weak::into_raw(Arc::downgrade(&self_ref.state)); let mut state = self_ref.state.write().unwrap(); if let Some(result) = state.result.take() { @@ -83,6 +82,7 @@ impl> Future for CallFuture { let method = &state.method; let args = state.arg.as_ref(); let payment = state.payment; + let state_ptr = Weak::into_raw(Arc::downgrade(&self_ref.state)); // SAFETY: // `callee`, being &[u8], is a readable sequence of bytes and therefore can be passed to ic0.call_new. // `method`, being &str, is a readable sequence of bytes and therefore can be passed to ic0.call_new.