From fd191e1ff562e79d5d9ffc09c761ee11a0f8021d Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Mon, 16 Oct 2023 20:01:26 +0900 Subject: [PATCH] [Connection] Fix ASAN crash issue --- .../Interop/Interop.Glib.cs | 27 +++++++++++++++++++ .../Interop/Interop.Libraries.cs | 1 + .../CellularProfile.cs | 4 +-- .../ConnectionInternalManager.cs | 6 ++--- .../ConnectionProfile.cs | 8 +++--- .../IAddressInformation.cs | 2 +- .../Tizen.Network.Connection/WiFiProfile.cs | 4 +-- 7 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 src/Tizen.Network.Connection/Interop/Interop.Glib.cs diff --git a/src/Tizen.Network.Connection/Interop/Interop.Glib.cs b/src/Tizen.Network.Connection/Interop/Interop.Glib.cs new file mode 100644 index 00000000000..a4961a70064 --- /dev/null +++ b/src/Tizen.Network.Connection/Interop/Interop.Glib.cs @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Glib + { + [DllImport(Libraries.Glib, EntryPoint = "g_free", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint Free(IntPtr data); + } +} diff --git a/src/Tizen.Network.Connection/Interop/Interop.Libraries.cs b/src/Tizen.Network.Connection/Interop/Interop.Libraries.cs index e4c53178bc3..4963b1752eb 100644 --- a/src/Tizen.Network.Connection/Interop/Interop.Libraries.cs +++ b/src/Tizen.Network.Connection/Interop/Interop.Libraries.cs @@ -20,5 +20,6 @@ internal static partial class Libraries { public const string Connection = "libcapi-network-connection.so.1"; public const string Libc = "libc.so.6"; + public const string Glib = "libglib-2.0.so.0"; } } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs index 91503be50de..7969f7ff6eb 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs @@ -63,7 +63,7 @@ public string Apn Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } @@ -112,7 +112,7 @@ public string HomeUri Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index a622a282278..637f3c0a52e 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -479,7 +479,7 @@ internal System.Net.IPAddress GetIPAddress(AddressFamily family) } string result = Marshal.PtrToStringAnsi(ip); - Interop.Libc.Free(ip); + Interop.Glib.Free(ip); Log.Info(Globals.LogTag, "IPAddress " + result + " (" + result.Length + ")"); if (result.Length == 0) { @@ -535,7 +535,7 @@ internal string GetProxy(AddressFamily family) } string result = Marshal.PtrToStringAnsi(ip); - Interop.Libc.Free(ip); + Interop.Glib.Free(ip); return result; } @@ -553,7 +553,7 @@ internal string GetMacAddress(ConnectionType type) } string result = Marshal.PtrToStringAnsi(mac); - Interop.Libc.Free(mac); + Interop.Glib.Free(mac); return result; } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs index df518f9d2fd..362e10f57a1 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs @@ -196,7 +196,7 @@ public string Id Log.Error(Globals.LogTag, "It failed to get id of connection profile, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } } @@ -217,7 +217,7 @@ public string Name Log.Error(Globals.LogTag, "It failed to get name of connection profile, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } } @@ -257,7 +257,7 @@ public string InterfaceName Log.Error(Globals.LogTag, "It failed to get network interface name, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } } @@ -391,7 +391,7 @@ public string ProxyAddress Log.Error(Globals.LogTag, "It failed to get proxy address, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); - Interop.Libc.Free(Value); + Interop.Glib.Free(Value); return result; } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs index ec3ec8f0321..d9d50c22b63 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs @@ -353,7 +353,7 @@ private System.Net.IPAddress ParseIPAddress(int ret, IntPtr addrPtr) string addr = Marshal.PtrToStringAnsi(addrPtr); if (addr == null || addr.Length == 0) return DefaultIPAddress(); - Interop.Libc.Free(addrPtr); + Interop.Glib.Free(addrPtr); return System.Net.IPAddress.Parse(addr); } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs index 6cfbc3337db..df370be5296 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs @@ -55,7 +55,7 @@ public string Essid Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(value); - Interop.Libc.Free(value); + Interop.Glib.Free(value); return result; } } @@ -76,7 +76,7 @@ public string Bssid Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(value); - Interop.Libc.Free(value); + Interop.Glib.Free(value); return result; } }