Electric-Coin-Company / zcash-swift-wallet-sdk

iOS light client Framework proof-of-concept
MIT License
37 stars 33 forks source link

Check pairing of deallocations vs allocations in rustBackend #1262

Closed LukasKorba closed 8 months ago

LukasKorba commented 8 months ago

Comment in review If I'm not mistaken rootsPtr is leaked because it's not deallocated. but as I can see there are other allocations that seem to me not deallocated properly.

LukasKorba commented 8 months ago

There are 2 leaks in total in the whole SDK, both 1 byte of memory.

Leak 1

ZcashRustBackend and method listTransparentReceivers(account: Int32)

Screenshot 2023-09-14 at 12 38 01

Leak 2

ZcashRustBackend and method putSaplingSubtreeRoots

Screenshot 2023-09-14 at 12 38 15
LukasKorba commented 8 months ago

Leak number 1 is probably a false positive.

The allocation is done in the rust

        let encodedKeysPtr = zcashlc_list_transparent_receivers(
            dbData.0,
            dbData.1,
            account,
            networkType.networkId
        )

and deallocation is handled in

        defer { zcashlc_free_keys(encodedKeysPtr) }

Leak number 2 deallocated in the code and after instruments check, this one no longer appears.

daira commented 8 months ago

Seems like this can be closed.