Release memory when open connection is failed 77/265777/4 accepted/tizen/unified/20211029.132506 submit/tizen/20211028.131731
authorwn.jang <wn.jang@samsung.com>
Thu, 28 Oct 2021 08:45:49 +0000 (17:45 +0900)
committerwn.jang <wn.jang@samsung.com>
Thu, 28 Oct 2021 09:58:42 +0000 (18:58 +0900)
Change-Id: I3172ee394b75ea8a63e747f24dfc0797ee6a0fad

server/vcd_server.c

index e80bc146c6c83d66cfb729195254d71eae10b02e..486b6cbfa5d806c483cd84a445786bdab8a17770 100644 (file)
@@ -1285,6 +1285,9 @@ int vcd_initialize(vce_request_callback_s *callback)
        ret = vc_db_initialize_for_daemon();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret);
+               if (TRUE != vcd_finalize()) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
+               }
                return ret;
        }
 
@@ -1299,17 +1302,26 @@ int vcd_initialize(vce_request_callback_s *callback)
        ret = vcd_engine_agent_init();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
+               if (TRUE != vcd_finalize()) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
+               }
                return ret;
        }
 
        if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
+               if (TRUE != vcd_finalize()) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
+               }
                return VCD_ERROR_OPERATION_FAILED;
        }
 
        /* Load engine */
        if (0 != vcd_engine_agent_load_current_engine(callback)) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
+               if (TRUE != vcd_finalize()) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
+               }
                return VCD_ERROR_OPERATION_FAILED;
        }
 
@@ -1319,7 +1331,10 @@ int vcd_initialize(vce_request_callback_s *callback)
 //     if (TRUE == __is_default_engine()) {
                /* Open dbus connection */
                if (0 != vcd_dbus_open_connection()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection");
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open connection");
+                       if (TRUE != vcd_finalize()) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
+                       }
                        return VCD_ERROR_OPERATION_FAILED;
                }
 //     }
@@ -1363,7 +1378,7 @@ bool vcd_finalize()
        }
 
        vcd_state_e state = vcd_config_get_service_state();
-       if (VCD_STATE_READY != state) {
+       if (VCD_STATE_NONE != state && VCD_STATE_READY != state) {
                if (VCD_STATE_RECORDING == state) {
                        vcd_recorder_stop();
                }
@@ -1396,8 +1411,10 @@ bool vcd_finalize()
                SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB : %d", ret);
        }
 
-       vcd_config_set_service_state(VCD_STATE_NONE);
-       vcdc_send_service_state(VCD_STATE_NONE);
+       if (VCD_STATE_NONE != state) {
+               vcd_config_set_service_state(VCD_STATE_NONE);
+               vcdc_send_service_state(VCD_STATE_NONE);
+       }
 
        /* Open dbus connection */
        if (0 != vcd_dbus_close_connection()) {