From 8b2cdb7e74de4379a920c16b019804381064e8d8 Mon Sep 17 00:00:00 2001 From: Viacheslav Kulish <32914239+vcoolish@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:30:52 -0800 Subject: [PATCH] Fix JVM synchronization issue (#4218) * Fix Java JVM leak * clean * apply to jni * [Misc]: Upgrade Rust toolchain to `nightly-2025-01-16` * [Misc]: Fix Clippy warnings --------- Co-authored-by: Satoshi Otomakan --- jni/java/wallet/core/java/GenericPhantomReference.java | 3 ++- .../kotlin/com/trustwallet/core/GenericPhantomReference.kt | 3 ++- rust/chains/tw_solana/src/transaction/versioned.rs | 2 +- rust/frameworks/tw_ton_sdk/src/boc/binary_writer.rs | 2 +- rust/frameworks/tw_ton_sdk/src/boc/raw.rs | 2 +- rust/tw_any_coin/src/wallet_connect_request.rs | 4 +--- rust/tw_encoding/src/hex.rs | 2 +- rust/tw_evm/src/message/eip712/message_types.rs | 2 +- rust/tw_misc/src/test_utils/json.rs | 4 ++-- tools/install-rust-dependencies | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jni/java/wallet/core/java/GenericPhantomReference.java b/jni/java/wallet/core/java/GenericPhantomReference.java index 1c5ee46dc76..ef7808b902e 100644 --- a/jni/java/wallet/core/java/GenericPhantomReference.java +++ b/jni/java/wallet/core/java/GenericPhantomReference.java @@ -4,12 +4,13 @@ import java.lang.ref.ReferenceQueue; import java.util.Set; import java.util.HashSet; +import java.util.Collections; public class GenericPhantomReference extends PhantomReference { private final long nativeHandle; private final OnDeleteCallback onDeleteCallback; - private static final Set references = new HashSet<>(); + private static final Set references = Collections.synchronizedSet(new HashSet<>()); private static final ReferenceQueue queue = new ReferenceQueue<>(); static { diff --git a/kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/GenericPhantomReference.kt b/kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/GenericPhantomReference.kt index b6ca8dd3653..0e2ffdd5b8f 100644 --- a/kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/GenericPhantomReference.kt +++ b/kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/GenericPhantomReference.kt @@ -2,6 +2,7 @@ package com.trustwallet.core import java.lang.ref.PhantomReference import java.lang.ref.ReferenceQueue +import java.util.Collections internal class GenericPhantomReference private constructor( referent: Any, @@ -10,7 +11,7 @@ internal class GenericPhantomReference private constructor( ) : PhantomReference(referent, queue) { companion object { - private val references: MutableSet = HashSet() + private val references: MutableSet = Collections.synchronizedSet(HashSet()) private val queue: ReferenceQueue = ReferenceQueue() init { diff --git a/rust/chains/tw_solana/src/transaction/versioned.rs b/rust/chains/tw_solana/src/transaction/versioned.rs index 18b81a81576..a43c73d4380 100644 --- a/rust/chains/tw_solana/src/transaction/versioned.rs +++ b/rust/chains/tw_solana/src/transaction/versioned.rs @@ -189,7 +189,7 @@ impl<'de> Deserialize<'de> for MessagePrefix { { struct PrefixVisitor; - impl<'de> Visitor<'de> for PrefixVisitor { + impl Visitor<'_> for PrefixVisitor { type Value = MessagePrefix; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/rust/frameworks/tw_ton_sdk/src/boc/binary_writer.rs b/rust/frameworks/tw_ton_sdk/src/boc/binary_writer.rs index 688d71f4e18..91d75f4430b 100644 --- a/rust/frameworks/tw_ton_sdk/src/boc/binary_writer.rs +++ b/rust/frameworks/tw_ton_sdk/src/boc/binary_writer.rs @@ -54,7 +54,7 @@ impl BinaryWriter { } else { self.write_bytes(&data[..data_len - 1])?; let last_byte = data[data_len - 1]; - let l = last_byte | 1 << (8 - rest_bits - 1); + let l = last_byte | (1 << (8 - rest_bits - 1)); self.write(8, l)?; } diff --git a/rust/frameworks/tw_ton_sdk/src/boc/raw.rs b/rust/frameworks/tw_ton_sdk/src/boc/raw.rs index 3b02a02d415..8a210da9006 100644 --- a/rust/frameworks/tw_ton_sdk/src/boc/raw.rs +++ b/rust/frameworks/tw_ton_sdk/src/boc/raw.rs @@ -263,7 +263,7 @@ fn write_raw_cell( if !full_bytes { writer.write_bytes(&data[..data_len_bytes - 1])?; let last_byte = data[data_len_bytes - 1]; - let l = last_byte | 1 << (8 - padding_bits - 1); + let l = last_byte | (1 << (8 - padding_bits - 1)); writer.write(8, l)?; } else { writer.write_bytes(data)?; diff --git a/rust/tw_any_coin/src/wallet_connect_request.rs b/rust/tw_any_coin/src/wallet_connect_request.rs index 22099edad58..77867b48925 100644 --- a/rust/tw_any_coin/src/wallet_connect_request.rs +++ b/rust/tw_any_coin/src/wallet_connect_request.rs @@ -16,8 +16,6 @@ impl WalletConnectRequest { #[inline] pub fn parse(coin: CoinType, input: &[u8]) -> SigningResult { let (ctx, entry) = coin_dispatcher(coin)?; - entry - .wallet_connect_parse_request(&ctx, input) - .map_err(SigningError::from) + entry.wallet_connect_parse_request(&ctx, input) } } diff --git a/rust/tw_encoding/src/hex.rs b/rust/tw_encoding/src/hex.rs index 5db6e8038a3..2d683c60e23 100644 --- a/rust/tw_encoding/src/hex.rs +++ b/rust/tw_encoding/src/hex.rs @@ -30,7 +30,7 @@ pub trait DecodeHex { fn decode_hex(&self) -> FromHexResult; } -impl<'a> DecodeHex for &'a str { +impl DecodeHex for &str { fn decode_hex(&self) -> FromHexResult { decode(self) } diff --git a/rust/tw_evm/src/message/eip712/message_types.rs b/rust/tw_evm/src/message/eip712/message_types.rs index 4a0d8f0aeae..85321686b15 100644 --- a/rust/tw_evm/src/message/eip712/message_types.rs +++ b/rust/tw_evm/src/message/eip712/message_types.rs @@ -38,7 +38,7 @@ pub struct CustomTypeBuilder<'a> { type_properties: &'a mut Vec, } -impl<'a> CustomTypeBuilder<'a> { +impl CustomTypeBuilder<'_> { pub fn add_property(&mut self, name: &str, property_type: PropertyType) -> &mut Self { self.type_properties.push(Property { name: name.to_string(), diff --git a/rust/tw_misc/src/test_utils/json.rs b/rust/tw_misc/src/test_utils/json.rs index 06da9d7ed63..93f5fa826f7 100644 --- a/rust/tw_misc/src/test_utils/json.rs +++ b/rust/tw_misc/src/test_utils/json.rs @@ -16,7 +16,7 @@ impl ToJson for Json { } } -impl<'a> ToJson for Cow<'a, str> { +impl ToJson for Cow<'_, str> { #[track_caller] fn to_json(&self) -> Json { self.as_ref().to_json() @@ -30,7 +30,7 @@ impl ToJson for String { } } -impl<'a> ToJson for &'a str { +impl ToJson for &str { #[track_caller] fn to_json(&self) -> Json { serde_json::from_str(self).expect("Error on deserializing JSON from string") diff --git a/tools/install-rust-dependencies b/tools/install-rust-dependencies index 1b12239c010..5ab14b69151 100755 --- a/tools/install-rust-dependencies +++ b/tools/install-rust-dependencies @@ -2,7 +2,7 @@ set -e -NIGHTLY="nightly-2024-06-13" +NIGHTLY="nightly-2025-01-16" rustup toolchain install $NIGHTLY rustup default $NIGHTLY