Fix to init g_system as NULL in error case 75/234875/5 submit/tizen/20200602.041357
authorSemun Lee <semun.lee@samsung.com>
Fri, 29 May 2020 10:06:24 +0000 (19:06 +0900)
committerSemun Lee <semun.lee@samsung.com>
Mon, 1 Jun 2020 04:15:44 +0000 (13:15 +0900)
Change-Id: I2a70043afafb76f1594313899a16f01679e82586
Signed-off-by: Semun Lee <semun.lee@samsung.com>
plugin/monitor/stc-plugin-monitor.c

index fc71c8c..1f08dc3 100755 (executable)
@@ -68,6 +68,17 @@ static gboolean __process_contr_reply(GIOChannel *source,
                                      GIOCondition condition,
                                      gpointer user_data);
 
+static void __free_system(stc_system_s *system)
+{
+       /* destroy monitored application tree */
+       if (system->apps)
+               g_hash_table_destroy(system->apps);
+       /* destroy restriction rules tree */
+       if (system->rstns)
+               g_hash_table_destroy(system->rstns);
+       FREE(system);
+}
+
 static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
 {
        GIOChannel *gio = NULL;
@@ -88,7 +99,8 @@ static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
        system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
        if (system->contr_sock < 0) {
                STC_LOGE("failed to open socket");
-               FREE(system);
+               __free_system(system);
+               g_system = NULL;
                return STC_ERROR_FAIL;
        }
 
@@ -349,7 +361,7 @@ stc_error_e stc_plugin_monitor_initialize(void)
        system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
        if (system->contr_sock < 0) {
                STC_LOGE("failed to open socket");
-               FREE(system);
+               __free_system(system);
                return STC_ERROR_FAIL;
        }
 
@@ -403,15 +415,8 @@ stc_error_e stc_plugin_monitor_deinitialize(void)
                g_system->contr_timer_id = 0;
        }
 
-       /* destroy monitored application tree */
-       g_hash_table_destroy(g_system->apps);
-       g_system->apps = NULL;
-
-       /* destroy restriction rules tree */
-       g_hash_table_destroy(g_system->rstns);
-       g_system->rstns = NULL;
-
-       FREE(g_system);
+       __free_system(g_system);
+       g_system = NULL;
 
        return STC_ERROR_NONE;
 }