Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KMP] Fix memory leak found in PublicKey #4097

Merged

Conversation

10gic
Copy link
Contributor

@10gic 10gic commented Nov 5, 2024

Description

Fix issue #4096

How to test

Types of changes

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

@10gic 10gic changed the title Fix memory lead found in public key in kmp binding [KMP] Fix memory leak found in PublicKey Nov 5, 2024
@10gic
Copy link
Contributor Author

10gic commented Nov 5, 2024

Before fixing:
kmp-memory-leak-public-key

After fixing:
kmp-memory-leak-public-key-fixing

Test case:

println("Test started")
val publicKeyHex =
    @Suppress("ktlint:standard:max-line-length")
    "044ba28b11af1561042b03b9d0f940446315af11358aa12d798050b3cf76265dab0f48b22ea1fc1f9560c969b966221f2821b746c4e56efaeaeec8689caf5843c9"
var i = 1
val publicKeyByteArray = publicKeyHex.hexToByteArray()
while (i <= 10_000_000) {
    val publicKey = PublicKey(publicKeyByteArray, PublicKeyType.SECP256k1Extended)
    if (i % 20_000 == 0) {
        println("Test case $i run")
    }
    i++
}
println("Test completed")

@10gic 10gic force-pushed the fix-kmp-memory-leak-public-key branch from 12ba04b to 57595dc Compare November 5, 2024 12:36
Copy link
Collaborator

@satoshiotomakan satoshiotomakan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, big thanks for the finding!

@satoshiotomakan satoshiotomakan merged commit 0479584 into trustwallet:dev Nov 6, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants