Skip to content

Commit

Permalink
[Connection] Fix ASAN crash issue (#5625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeonahMoon authored and hinohie committed Oct 25, 2023
1 parent 7bf9836 commit 31f784e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
27 changes: 27 additions & 0 deletions src/Tizen.Network.Connection/Interop/Interop.Glib.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/Tizen.Network.Connection/Interop/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -535,7 +535,7 @@ internal string GetProxy(AddressFamily family)
}

string result = Marshal.PtrToStringAnsi(ip);
Interop.Libc.Free(ip);
Interop.Glib.Free(ip);
return result;
}

Expand All @@ -553,7 +553,7 @@ internal string GetMacAddress(ConnectionType type)
}

string result = Marshal.PtrToStringAnsi(mac);
Interop.Libc.Free(mac);
Interop.Glib.Free(mac);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 31f784e

Please sign in to comment.