[Bluetooth] Fix ASAN crash issue (#5624)
authorWootak Jung <wootak.jung@samsung.com>
Tue, 24 Oct 2023 03:04:31 +0000 (12:04 +0900)
committerGitHub <noreply@github.com>
Tue, 24 Oct 2023 03:04:31 +0000 (12:04 +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 576a6e287cf1506ae88bb4fda76ccc5f7b9a9f35..ee7a1e1cd98fdb475077ab683867bf44f7d8f1dc 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 99a856d1f5f83d6f6f24a52fbc8518b0f2d3b04a..d74b045fa0f88a6eab1bbc140594d62b4317b51e 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 890c80e3e4ac49517268805f3df88cd6ee18b5f5..4cd0a805106531230867f94233ce767f239a4438 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;