[Multimedia] Fix ASAN crash issue (#5699)
authorHaesu Gwon <haesu.gwon@samsung.com>
Mon, 6 Nov 2023 08:03:28 +0000 (17:03 +0900)
committerGitHub <noreply@github.com>
Mon, 6 Nov 2023 08:03:28 +0000 (17:03 +0900)
* [Multimedia] Fix ASAN crash issue

24 files changed:
src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs [deleted file]
src/Tizen.Content.MediaContent/Interop/Interop.Libraries.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/InteropHelper.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs
src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerTrackInfo.cs
src/Tizen.Multimedia.MediaPlayer/Player/StreamInfo.cs
src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs [deleted file]
src/Tizen.Multimedia.Metadata/Interop/Interop.Libraries.cs
src/Tizen.Multimedia.Metadata/MetadataEditor/MetadataEditor.cs
src/Tizen.Multimedia.Metadata/MetadataExtractor/Metadata.cs
src/Tizen.Multimedia.Metadata/MetadataExtractor/MetadataExtractor.cs
src/Tizen.Multimedia.Metadata/MetadataExtractor/MetadataExtractorExtensions.cs
src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageEncoder.cs
src/Tizen.Multimedia.Util/ThumbnailExtractor/ThumbnailExtractor.cs
src/Tizen.Multimedia.Vision/MediaVision/EngineConfiguration.cs
src/Tizen.Multimedia.Vision/MediaVision/FaceRecognitionModel.cs
src/Tizen.Multimedia.Vision/MediaVision/SurveillanceEngine.cs
src/Tizen.Multimedia/AssemblyAttrs.cs
src/Tizen.Multimedia/Common.Internal/LibcSupport.cs [deleted file]
src/Tizen.Multimedia/Interop/Interop.Libc.cs
src/Tizen.Multimedia/Interop/Interop.Libraries.cs

diff --git a/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs b/src/Tizen.Content.MediaContent/Interop/Interop.Libc.cs
deleted file mode 100755 (executable)
index 825599e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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 Libc
-    {
-        [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
-        internal static extern int Free(IntPtr ptr);
-    }
-}
index 67fdba7..991cc43 100755 (executable)
@@ -19,6 +19,5 @@ internal static partial class Interop
     internal static partial class Libraries
     {
         public const string MediaContent = "libcapi-content-media-content.so.0";
-        public const string Libc = "libc.so.6";
     }
 }
index e40b1f5..368985e 100644 (file)
@@ -39,7 +39,7 @@ namespace Tizen.Content.MediaContent
             }
             finally
             {
-                Interop.Libc.Free(val);
+                Marshal.FreeHGlobal(val);
             }
         }
 
index ef0303e..708b9bd 100644 (file)
@@ -517,7 +517,7 @@ namespace Tizen.Content.MediaContent
                 var current = path;
                 for (int i = 0; i < length; i++)
                 {
-                    Interop.Libc.Free(Marshal.ReadIntPtr(current));
+                    Marshal.FreeHGlobal(current);
                     current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr)));
                 }
             }
index 46b0798..4ed0e53 100644 (file)
@@ -1395,7 +1395,7 @@ namespace Tizen.Multimedia
                 }
                 finally
                 {
-                    LibcSupport.Free(val);
+                    Marshal.FreeHGlobal(val);
                 }
             }
 
@@ -1426,7 +1426,7 @@ namespace Tizen.Multimedia
                 }
                 finally
                 {
-                    LibcSupport.Free(val);
+                    Marshal.FreeHGlobal(val);
                 }
             }
 
index 5cb0007..806f479 100644 (file)
@@ -121,7 +121,9 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                LibcSupport.Free(code);
+                // LibcSupport.Free(code);
+                // Marshal.FreeHGlobal(Marshal.ReadIntPtr(code));
+                Marshal.FreeHGlobal(code);
             }
         }
 
index 3f0519c..67674e5 100644 (file)
@@ -222,8 +222,8 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                LibcSupport.Free(audioPtr);
-                LibcSupport.Free(videoPtr);
+                Marshal.FreeHGlobal(audioPtr);
+                Marshal.FreeHGlobal(videoPtr);
             }
         }
 
@@ -394,7 +394,7 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                LibcSupport.Free(ptr);
+                Marshal.FreeHGlobal(ptr);
             }
         }
 
diff --git a/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs b/src/Tizen.Multimedia.Metadata/Interop/Interop.Libc.cs
deleted file mode 100644 (file)
index 8e0fa30..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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 Libc
-    {
-        [DllImport(Libraries.Libc, EntryPoint = "free")]
-        public static extern void Free(IntPtr userData);
-    }
-}
index df5d155..01ba226 100644 (file)
@@ -20,6 +20,5 @@ internal static partial class Interop
     {
         public const string MetadataEditor = "libcapi-media-metadata-editor.so";
         public const string MetadataExtractor = "libcapi-media-metadata-extractor.so";
-        public const string Libc = "libc.so.6";
     }
 }
index 79dc010..b9d723c 100644 (file)
@@ -18,6 +18,8 @@ using System;
 using System.IO;
 using System.Runtime.InteropServices;
 
+using Native = Interop.MetadataEditor;
+
 namespace Tizen.Multimedia
 {
     /// <summary>
@@ -72,11 +74,11 @@ namespace Tizen.Multimedia
                 throw new ArgumentException($"{nameof(path)} is a zero-length string.", nameof(path));
             }
 
-            Interop.MetadataEditor.Create(out _handle).ThrowIfError("Failed to create metadata");
+            Native.Create(out _handle).ThrowIfError("Failed to create metadata");
 
             try
             {
-                Interop.MetadataEditor.SetPath(Handle, path).ThrowIfError("Failed to set path");
+                Native.SetPath(Handle, path).ThrowIfError("Failed to set path");
 
                 _isFileReadOnly = File.GetAttributes(path).HasFlag(FileAttributes.ReadOnly);
             }
@@ -93,14 +95,14 @@ namespace Tizen.Multimedia
 
             try
             {
-                Interop.MetadataEditor.GetMetadata(Handle, attr, out val)
+                Native.GetMetadata(Handle, attr, out val)
                     .ThrowIfError("Failed to get metadata");
 
                 return Marshal.PtrToStringAnsi(val);
             }
             finally
             {
-                Interop.Libc.Free(val);
+                Marshal.FreeHGlobal(val);
             }
         }
 
@@ -111,7 +113,7 @@ namespace Tizen.Multimedia
                 throw new InvalidOperationException("The media file is read-only.");
             }
 
-            Interop.MetadataEditor.SetMetadata(Handle, attr, value).ThrowIfError("Failed to set value");
+            Native.SetMetadata(Handle, attr, value).ThrowIfError("Failed to set value");
         }
 
         /// <summary>
@@ -445,7 +447,7 @@ namespace Tizen.Multimedia
                 throw new InvalidOperationException("The media file is read-only.");
             }
 
-            Interop.MetadataEditor.UpdateMetadata(Handle).ThrowIfError("Failed to update file");
+            Native.UpdateMetadata(Handle).ThrowIfError("Failed to update file");
         }
 
         /// <summary>
@@ -480,7 +482,7 @@ namespace Tizen.Multimedia
 
             try
             {
-                Interop.MetadataEditor.GetPicture(Handle, index, out data, out var size, out mimeType).
+                Native.GetPicture(Handle, index, out data, out var size, out mimeType).
                     ThrowIfError("Failed to get the value");
 
                 if (size > 0)
@@ -497,12 +499,12 @@ namespace Tizen.Multimedia
             {
                 if (data != IntPtr.Zero)
                 {
-                    Interop.Libc.Free(data);
+                    Marshal.FreeHGlobal(data);
                 }
 
                 if (mimeType != IntPtr.Zero)
                 {
-                    Interop.Libc.Free(mimeType);
+                    Marshal.FreeHGlobal(mimeType);
                 }
             }
         }
@@ -541,7 +543,7 @@ namespace Tizen.Multimedia
                 throw new InvalidOperationException("The media file is read-only.");
             }
 
-            Interop.MetadataEditor.AddPicture(Handle, path).
+            Native.AddPicture(Handle, path).
                 ThrowIfError("Failed to append picture");
         }
 
@@ -579,7 +581,7 @@ namespace Tizen.Multimedia
                 throw new InvalidOperationException("The media file is read-only.");
             }
 
-            Interop.MetadataEditor.RemovePicture(Handle, index).ThrowIfError("Failed to remove picture");
+            Native.RemovePicture(Handle, index).ThrowIfError("Failed to remove picture");
         }
 
         /// <summary>
@@ -603,7 +605,7 @@ namespace Tizen.Multimedia
             {
                 if (_handle != IntPtr.Zero)
                 {
-                    Interop.MetadataEditor.Destroy(_handle);
+                    Native.Destroy(_handle);
                     _handle = IntPtr.Zero;
                 }
 
index a37caf0..d5ca764 100644 (file)
@@ -16,7 +16,6 @@
 
 using System;
 using System.Diagnostics;
-using static Interop.MetadataExtractor;
 
 namespace Tizen.Multimedia
 {
index 83911e0..071fa49 100644 (file)
@@ -18,6 +18,8 @@ using System;
 using System.IO;
 using System.Runtime.InteropServices;
 
+using Native = Interop.MetadataExtractor;
+
 namespace Tizen.Multimedia
 {
     /// <summary>
@@ -33,7 +35,7 @@ namespace Tizen.Multimedia
         private void Create(Func<MetadataExtractorError> initFunc)
         {
             MetadataExtractorRetValidator.ThrowIfError(
-                Interop.MetadataExtractor.Create(out _handle), "Failed to create metadata");
+                Native.Create(out _handle), "Failed to create metadata");
 
             try
             {
@@ -62,7 +64,7 @@ namespace Tizen.Multimedia
                 throw new ArgumentNullException(nameof(path));
             }
 
-            Create(() => Interop.MetadataExtractor.SetPath(_handle, path));
+            Create(() => Native.SetPath(_handle, path));
         }
 
         /// <summary>
@@ -89,7 +91,7 @@ namespace Tizen.Multimedia
 
             try
             {
-                Create(() => Interop.MetadataExtractor.SetBuffer(_handle, _buffer, buffer.Length));
+                Create(() => Native.SetBuffer(_handle, _buffer, buffer.Length));
             }
             catch (Exception)
             {
@@ -146,7 +148,7 @@ namespace Tizen.Multimedia
             {
                 int size = 0;
 
-                var ret = Interop.MetadataExtractor.GetArtwork(Handle, out data, out size, out mimeType);
+                var ret = Native.GetArtwork(Handle, out data, out size, out mimeType);
                 MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value");
 
                 if (size > 0)
@@ -161,8 +163,8 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                Interop.Libc.Free(data);
-                Interop.Libc.Free(mimeType);
+                Marshal.FreeHGlobal(data);
+                Marshal.FreeHGlobal(mimeType);
             }
         }
 
@@ -182,7 +184,7 @@ namespace Tizen.Multimedia
             {
                 uint timestamp = 0;
 
-                var ret = Interop.MetadataExtractor.GetSynclyrics(Handle, index, out timestamp, out lyrics);
+                var ret = Native.GetSynclyrics(Handle, index, out timestamp, out lyrics);
                 MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get sync lyrics");
 
                 if (lyrics == IntPtr.Zero)
@@ -194,7 +196,7 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                Interop.Libc.Free(lyrics);
+                Marshal.FreeHGlobal(lyrics);
             }
         }
 
@@ -213,7 +215,7 @@ namespace Tizen.Multimedia
             {
                 int size = 0;
 
-                var ret = Interop.MetadataExtractor.GetFrame(Handle, out data, out size);
+                var ret = Native.GetFrame(Handle, out data, out size);
                 MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value");
 
                 if (size == 0)
@@ -228,7 +230,7 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                Interop.Libc.Free(data);
+                Marshal.FreeHGlobal(data);
             }
         }
 
@@ -250,7 +252,7 @@ namespace Tizen.Multimedia
             {
                 int size = 0;
 
-                var ret = Interop.MetadataExtractor.GetFrameAtTime(Handle, timeStamp, accurate, out data, out size);
+                var ret = Native.GetFrameAtTime(Handle, timeStamp, accurate, out data, out size);
                 MetadataExtractorRetValidator.ThrowIfError(ret, "Failed to get value");
 
                 if (size == 0)
@@ -265,7 +267,7 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                Interop.Libc.Free(data);
+                Marshal.FreeHGlobal(data);
             }
         }
 
@@ -303,7 +305,7 @@ namespace Tizen.Multimedia
 
             if (_handle != IntPtr.Zero)
             {
-                var ret = Interop.MetadataExtractor.Destroy(_handle);
+                var ret = Native.Destroy(_handle);
                 if (ret != MetadataExtractorError.None)
                 {
                     Log.Error(typeof(MetadataExtractor).FullName, $"DestroyHandle failed : {ret}.");
index f3b72ee..756db79 100644 (file)
@@ -18,7 +18,6 @@ using System;
 using System.Diagnostics;
 using System.Runtime.InteropServices;
 using Native = Interop.MetadataExtractor;
-using static Interop;
 
 namespace Tizen.Multimedia
 {
@@ -38,7 +37,7 @@ namespace Tizen.Multimedia
             }
             finally
             {
-                Libc.Free(valuePtr);
+                Marshal.FreeHGlobal(valuePtr);
             }
         }
 
index 4e49285..6feb12e 100644 (file)
@@ -66,7 +66,7 @@ internal static partial class Interop
             }
             finally
             {
-                Tizen.Multimedia.LibcSupport.Free(valuePtr);
+                Marshal.FreeHGlobal(valuePtr);
             }
         }
 
@@ -141,7 +141,7 @@ internal static partial class Interop
             }
             finally
             {
-                Tizen.Multimedia.LibcSupport.Free(valuePtr);
+                Marshal.FreeHGlobal(valuePtr);
             }
         }
 
@@ -161,8 +161,8 @@ internal static partial class Interop
             }
             finally
             {
-                Tizen.Multimedia.LibcSupport.Free(playlistName);
-                Tizen.Multimedia.LibcSupport.Free(index);
+                Marshal.FreeHGlobal(playlistName);
+                Marshal.FreeHGlobal(index);
             }
         }
 
@@ -184,7 +184,7 @@ internal static partial class Interop
             }
             finally
             {
-                Tizen.Multimedia.LibcSupport.Free(valuePtr);
+                Marshal.FreeHGlobal(valuePtr);
             }
         }
 
index 1ec4f87..e2eae47 100644 (file)
@@ -247,7 +247,7 @@ namespace Tizen.Multimedia.Util
             {
                 if (outBuffer != IntPtr.Zero)
                 {
-                    LibcSupport.Free(outBuffer);
+                    Marshal.FreeHGlobal(outBuffer);
                 }
 
                 if (imageHandle != IntPtr.Zero)
index df40539..f9af44e 100644 (file)
@@ -131,7 +131,7 @@ namespace Tizen.Multimedia.Util
             }
             finally
             {
-                Interop.Libc.Free(outBuffer);
+                Marshal.FreeHGlobal(outBuffer);
             }
         }
 
index c939838..da21203 100644 (file)
@@ -18,6 +18,7 @@ using System;
 using System.IO;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Runtime.InteropServices;
 using Native = Interop.ThumbnailExtractor;
 
 namespace Tizen.Multimedia.Util
@@ -290,7 +291,7 @@ namespace Tizen.Multimedia.Util
             {
                 if (thumbData != IntPtr.Zero)
                 {
-                    LibcSupport.Free(thumbData);
+                    Marshal.FreeHGlobal(thumbData);
                 }
             }
         }
index 38cda12..16be9b7 100755 (executable)
@@ -148,7 +148,7 @@ namespace Tizen.Multimedia.Vision
             }
             finally
             {
-                LibcSupport.Free(ptr);
+                Marshal.FreeHGlobal(ptr);
             }
         }
 
@@ -178,7 +178,7 @@ namespace Tizen.Multimedia.Vision
                 var current = values;
                 for (int i = 0; i < size; i++)
                 {
-                    LibcSupport.Free(Marshal.ReadIntPtr(current));
+                    Marshal.FreeHGlobal(current);
                     current = (IntPtr)((long)current + Marshal.SizeOf(typeof(IntPtr)));
                 }
             }
index 8d0f730..4770a52 100755 (executable)
@@ -101,7 +101,7 @@ namespace Tizen.Multimedia.Vision
                 {
                     if (unmangedArray != IntPtr.Zero)
                     {
-                        LibcSupport.Free(unmangedArray);
+                        Marshal.FreeHGlobal(unmangedArray);
                     }
                 }
             }
index 0d52836..cfbd25a 100755 (executable)
@@ -93,7 +93,7 @@ namespace Tizen.Multimedia.Vision
                 }
                 finally
                 {
-                    LibcSupport.Free(roiPtr);
+                    Marshal.FreeHGlobal(roiPtr);
                 }
             }
             set
index 51179d6..ed3637c 100644 (file)
@@ -41,6 +41,8 @@ using System.Runtime.CompilerServices;
 
 [assembly: InternalsVisibleTo("Tizen.Multimedia.Radio, " + PublicKey.Value)]
 
+[assembly: InternalsVisibleTo("Tizen.Multimedia.Metadata, " + PublicKey.Value)]
+
 internal static class PublicKey
 {
     internal const string Value =
diff --git a/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs b/src/Tizen.Multimedia/Common.Internal/LibcSupport.cs
deleted file mode 100644 (file)
index c888cd7..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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;
-
-namespace Tizen.Multimedia
-{
-    internal static class LibcSupport
-    {
-        internal static void Free(IntPtr ptr)
-        {
-            Interop.Libc.Free(ptr);
-        }
-    }
-}
index 407352c..96ba300 100644 (file)
@@ -29,10 +29,10 @@ namespace Tizen.Multimedia
                 internal const int R_OK = 0x04;
             }
 
-            [DllImport(Libraries.Libc, EntryPoint = "free")]
+            [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
             public static extern void Free(IntPtr ptr);
 
-            [DllImport(Libraries.Libc, EntryPoint = "access")]
+            [DllImport(Libraries.Libc, EntryPoint = "access", CallingConvention = CallingConvention.Cdecl)]
             public static extern int Access(string path, int mode);
         }
     }
index f0ce791..cd7fdf5 100644 (file)
@@ -23,6 +23,7 @@ namespace Tizen.Multimedia
             public const string SoundManager = "libcapi-media-sound-manager.so.0";
             public const string MediaTool = "libcapi-media-tool.so.0";
             public const string Libc = "libc.so.6";
+            public const string GLib = "libglib-2.0.so.0";
         }
     }
 }