Fix GetLocalOobData memory leak (#2725)
authorWootak Jung <wootak.jung@samsung.com>
Wed, 10 Mar 2021 05:28:50 +0000 (14:28 +0900)
committerGitHub <noreply@github.com>
Wed, 10 Mar 2021 05:28:50 +0000 (14:28 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs

index b2788c5..c2e8249 100644 (file)
@@ -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;
         }