From 69fdd8c824e1cd58afe72131a2dc5c6fccbf47b0 Mon Sep 17 00:00:00 2001 From: urmain Date: Mon, 29 Apr 2019 17:22:42 +0900 Subject: [PATCH] [STT/TTS] Fix desctructor to call dispose (#596) (#800) Signed-off-by: sooyeon.kim --- src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs | 36 ++++++++++++++++---------- src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs | 38 ++++++++++++++++++---------- 2 files changed, 47 insertions(+), 27 deletions(-) mode change 100755 => 100644 src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs mode change 100755 => 100644 src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs diff --git a/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs b/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs old mode 100755 new mode 100644 index c057a86..76f70ca --- a/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs +++ b/src/Tizen.Uix.Stt/Tizen.Uix.Stt/SttClient.cs @@ -364,6 +364,14 @@ namespace Tizen.Uix.Stt } /// + /// Destructor to destroy a STT instance. + /// + ~SttClient() + { + Dispose(false); + } + + /// /// Event to be invoked when the recognition is done. /// /// 3 @@ -1494,6 +1502,7 @@ namespace Tizen.Uix.Stt public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// @@ -1507,19 +1516,20 @@ namespace Tizen.Uix.Stt { if (!disposedValue) { - if (disposing) - { - lock (thisLock) - { - SttError error = SttDestroy(_handle); - if (error != SttError.None) - { - Log.Error(LogTag, "Destroy Failed with error " + error); - } - } - } - - disposedValue = true; + lock (thisLock) + { + if (_handle != IntPtr.Zero) + { + SttError error = SttDestroy(_handle); + if (error != SttError.None) + { + Log.Error(LogTag, "Destroy Failed with error " + error); + } + _handle = IntPtr.Zero; + } + } + + disposedValue = true; } } } diff --git a/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs b/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs old mode 100755 new mode 100644 index 7dab0ae..6a53f5c --- a/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs +++ b/src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs @@ -240,6 +240,14 @@ namespace Tizen.Uix.Tts } /// + /// Destructor to destroy TtsClient handle. + /// + ~TtsClient() + { + Dispose(false); + } + + /// /// Event to be invoked when TTS state changes. /// /// 3 @@ -1041,6 +1049,7 @@ namespace Tizen.Uix.Tts public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// @@ -1053,20 +1062,21 @@ namespace Tizen.Uix.Tts protected virtual void Dispose(bool disposing) { if (!disposedValue) - { - if (disposing) - { - lock (thisLock) - { - TtsError error = TtsDestroy(_handle); - if (error != TtsError.None) - { - Log.Error(LogTag, "Destroy Failed with error " + error); - } - } - } - - disposedValue = true; + { + lock (thisLock) + { + if (_handle != IntPtr.Zero) + { + TtsError error = TtsDestroy(_handle); + if (error != TtsError.None) + { + Log.Error(LogTag, "Destroy Failed with error " + error); + } + _handle = IntPtr.Zero; + } + } + + disposedValue = true; } } } -- 2.7.4