Skip to content

Commit

Permalink
[Bluetooth] Fix ASAN crash issue (#5624)
Browse files Browse the repository at this point in the history
- Use g_free for data allocated by g_malloc

Signed-off-by: Wootak Jung <[email protected]>
  • Loading branch information
wootak-jung authored Oct 24, 2023
1 parent 168fe31 commit 27de0d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/Tizen.Network.Bluetooth/Interop/Interop.Glib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ internal static partial class Glib

[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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,14 @@ internal BluetoothOobData GetLocalOobData()
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ internal IList<string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData,
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;
Expand Down Expand Up @@ -295,10 +295,10 @@ internal IList<string> GetScanResultSvcSolicitationUuids(BluetoothLeScanData sca
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;
Expand Down Expand Up @@ -417,7 +417,7 @@ internal ManufacturerData GetScanResultManufacturerData(BluetoothLeScanData scan
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;
Expand Down

0 comments on commit 27de0d2

Please sign in to comment.