[Bluetooth] Fix ASAN crash issue (#5624)
authorWootak Jung <wootak.jung@samsung.com>
Tue, 24 Oct 2023 03:04:31 +0000 (12:04 +0900)
committerSW Kim <sw0312.kim@samsung.com>
Fri, 17 Nov 2023 04:08:06 +0000 (13:08 +0900)
- Use g_free for data allocated by g_malloc

Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Interop/Interop.Glib.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs

index 576a6e2..ee7a1e1 100644 (file)
@@ -26,5 +26,8 @@ internal static partial class Interop
 
         [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)]
         internal static extern uint IdleAdd(GSourceFunc d, IntPtr data);
+
+        [DllImport(Libraries.Glib, EntryPoint = "g_free", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern void Gfree(IntPtr ptr);
     }
 }
index 99a856d..d74b045 100644 (file)
@@ -534,14 +534,14 @@ namespace Tizen.Network.Bluetooth
                 byte[] hashArr = new byte[hashLength];
                 Marshal.Copy(hash, hashArr, 0, hashLength);
                 oobData.HashValue = hashArr;
-                Interop.Libc.Free(hash);
+                Interop.Glib.Gfree(hash);
             }
 
             if (randomizerLength > 0) {
                 byte[] randomizerArr = new byte[randomizerLength];
                 Marshal.Copy(randomizer, randomizerArr, 0, randomizerLength);
                 oobData.RandomizerValue = randomizerArr;
-                Interop.Libc.Free(randomizer);
+                Interop.Glib.Gfree(randomizer);
             }
 
             return oobData;
index 890c80e..4cd0a80 100644 (file)
@@ -187,10 +187,10 @@ namespace Tizen.Network.Bluetooth
             foreach (IntPtr uuids in uuidList)
             {
                 list.Add(Marshal.PtrToStringAnsi(uuids));
-                Interop.Libc.Free(uuids);
+                Interop.Glib.Gfree(uuids);
             }
 
-            Interop.Libc.Free(uuidListArray);
+            Interop.Glib.Gfree(uuidListArray);
             Marshal.FreeHGlobal(scanDataStruct.AdvData);
             Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return list;
@@ -295,10 +295,10 @@ namespace Tizen.Network.Bluetooth
             foreach (IntPtr uuids in uuidList)
             {
                 list.Add(Marshal.PtrToStringAnsi(uuids));
-                Interop.Libc.Free(uuids);
+                Interop.Glib.Gfree(uuids);
             }
 
-            Interop.Libc.Free(uuidListArray);
+            Interop.Glib.Gfree(uuidListArray);
             Marshal.FreeHGlobal(scanDataStruct.AdvData);
             Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return list;
@@ -417,7 +417,7 @@ namespace Tizen.Network.Bluetooth
                 Marshal.Copy(manufData, data.Data, 0, data.DataLength);
             }
 
-            Interop.Libc.Free(manufData);
+            Interop.Glib.Gfree(manufData);
             Marshal.FreeHGlobal(scanDataStruct.AdvData);
             Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return data;