Fix bug of unexpected crash 75/31075/3
authorJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 1 Dec 2014 09:13:47 +0000 (10:13 +0100)
committerJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 1 Dec 2014 13:46:44 +0000 (14:46 +0100)
Bug-tizen: TC-2182

Change-Id: I04470dec605b58afa5d5bed56502f5ab459de97c
Signed-off-by: José Bollo <jose.bollo@open.eurogiciel.org>
server/mm_sound_hal.c
server/mm_sound_plugin.c

index bcfc11a..7855bbd 100644 (file)
@@ -163,7 +163,7 @@ int MMSoundMgrHALInit(const char *targetdir)
     return AUDIO_HAL_STATE_SUCCESS;
 
 err_out_and_free:
-    free(g_hal_plugin);
+    MMSoundPluginRelease(g_hal_plugin);
     g_hal_plugin = NULL;
     debug_fleave();
     return AUDIO_HAL_STATE_ERROR_INTERNAL;
index 8640842..c9d1147 100644 (file)
@@ -18,7 +18,7 @@
  * limitations under the License.
  *
  */
+
 #include <stdlib.h>
 #include <string.h>
 
@@ -36,6 +36,12 @@ static char* __strcatdup(const char *str1, const char *str2);
 static int _MMSoundPluginGetList(const char *plugdir ,char ***list);
 static int _MMSoundPluginDestroyList(char **list);
 
+/* default "empty list" used in case of error */
+static MMSoundPluginType empty_plugin_list = {
+    .type = MM_SOUND_PLUGIN_TYPE_NONE,
+    .module = NULL
+};
+
 char* MMSoundPluginGetTypeName(int type)
 {
     static char *typename[] = {
@@ -64,8 +70,10 @@ int MMSoundPluginScan(const char *plugindir, const int type, MMSoundPluginType *
 
     debug_msg(" Plugin dir :: %s \n", plugindir);
     err = _MMSoundPluginGetList(plugindir, &list);
-    if (err != MM_ERROR_NONE)
+    if (err != MM_ERROR_NONE) {
+        *pluginlist = &empty_plugin_list;
         return err;
+    }
 
     while((item = list[index++]) != NULL) {
         if(MMSoundPluginOpen(item, &plugin[plugin_index]) != MM_ERROR_NONE) {
@@ -107,7 +115,8 @@ int MMSoundPluginRelease(MMSoundPluginType *pluginlist)
         MMSoundPluginClose(&pluginlist[loop++]);
     }
 
-    free (pluginlist);
+    if (pluginlist != &empty_plugin_list)
+        free (pluginlist);
 
     debug_fleave ();