From d29f5d53cabee80aaa8e24603f9b6b23a10ef4a6 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Wed, 10 Mar 2021 14:42:02 +0900 Subject: [PATCH] Fix GetLocalOobData memory leak (#2724) Signed-off-by: Wootak Jung --- .../Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs index b2788c5..c2e8249 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs @@ -530,13 +530,20 @@ namespace Tizen.Network.Bluetooth BluetoothErrorFactory.ThrowBluetoothException(ret); } - byte[] hashArr = new byte[hashLength]; - Marshal.Copy(hash, hashArr, 0, hashLength); - byte[] randomizerArr = new byte[randomizerLength]; - Marshal.Copy(randomizer, randomizerArr, 0, randomizerLength); + if (hashLength > 0) { + byte[] hashArr = new byte[hashLength]; + Marshal.Copy(hash, hashArr, 0, hashLength); + oobData.HashValue = hashArr; + Interop.Libc.Free(hash); + } + + if (randomizerLength > 0) { + byte[] randomizerArr = new byte[randomizerLength]; + Marshal.Copy(randomizer, randomizerArr, 0, randomizerLength); + oobData.RandomizerValue = randomizerArr; + Interop.Libc.Free(randomizer); + } - oobData.HashValue = hashArr; - oobData.RandomizerValue = randomizerArr; return oobData; } -- 2.7.4