fix memory leak and add on-demand timeout 85/136785/1 accepted/tizen/3.0/common/20170706.101303 accepted/tizen/3.0/ivi/20170705.230524 accepted/tizen/3.0/mobile/20170705.230510 accepted/tizen/3.0/wearable/20170705.230520 submit/tizen_3.0/20170703.071958
authorjkjo92 <jkjo92@samsung.com>
Mon, 3 Jul 2017 07:04:58 +0000 (16:04 +0900)
committerjkjo92 <jkjo92@samsung.com>
Mon, 3 Jul 2017 07:04:58 +0000 (16:04 +0900)
Change-Id: I879d34f51c15f46dc3f9620f7148587db35e5e46
Signed-off-by: jkjo92 <jkjo92@samsung.com>
server/fido_server.c

index 73c9c80..6aee642 100755 (executable)
 #include "fido-stub.h"
 
 #define _FIDO_SERVICE_DBUS_PATH       "/org/tizen/fido"
+
+/* timeout for terminating on-demand service */
+#define _FIDO_SERVICE_MIN_TIMEOUT      1       /* seconds */
+#define _FIDO_SERVICE_BOOTUP_TIMEOUT   30      /* seconds */
+#define _FIDO_SERVICE_PROCESS_TIMEOUT  90      /* seconds */
+
 static guint owner_id = 0;
 //GDBusObjectManagerServer *fido_dbus_mgr = NULL;
 static Fido* fido_dbus_obj = NULL;
+static GMainLoop *mainloop = NULL;
+static guint timeout_handle;
 
 //TODO : current assumption is, ASM will handle multiple request queueing
 
@@ -75,6 +83,7 @@ typedef struct _process_cb_data {
 } _process_cb_data_t;
 
 static void __process_dereg_queue(_dereg_q_t *dereg_q);
+static void __set_timeout(int seconds);
 
 static char**
 __create_empty_json_2d_array(void)
@@ -180,6 +189,11 @@ _send_process_response(_process_cb_data_t *cb_data, int tz_err_code, char *uaf_r
 {
        _INFO("_send_process_response");
 
+       if (cb_data == NULL) {
+               SAFE_DELETE(uaf_response_json);
+               return;
+       }
+
        /*TODO*/
        _dbus_info_t *dbus_info = (_dbus_info_t *)(cb_data->dbus_info);
        if (dbus_info != NULL) {
@@ -674,6 +688,7 @@ __handle_auth(_process_cb_data_t *cb_data, _matched_auth_data_t *matched_auth)
                _ERR("ASM in data missing");
                _send_process_response(cb_data, FIDO_ERROR_NO_SUITABLE_AUTHENTICATOR, NULL);
 
+               _free_fido_asm_auth_in(auth_asm_in);
                SAFE_DELETE(version);
 
                return;
@@ -1253,6 +1268,9 @@ __facet_id_cb(int err, const char *facet_id, void *user_data)
 gboolean
 _dbus_on_fido_init(Fido *object, GDBusMethodInvocation *invocation)
 {
+       _INFO("_dbus_on_fido_init");
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
+
        fido_complete_fido_uaf_init(object, invocation, FIDO_ERROR_NONE);
 
        return true;
@@ -1261,6 +1279,9 @@ _dbus_on_fido_init(Fido *object, GDBusMethodInvocation *invocation)
 gboolean
 _dbus_on_fido_deinit(Fido *object, GDBusMethodInvocation *invocation)
 {
+       _INFO("_dbus_on_fido_deinit");
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
+
        if (is_allowed_to_call(invocation, _FIDO_CLIENT_PRIVILEGE) == false) {
                fido_complete_fido_uaf_deinit(object, invocation, FIDO_ERROR_PERMISSION_DENIED);
        } else {
@@ -1275,6 +1296,8 @@ gboolean
 _dbus_on_fido_discover(Fido *object, GDBusMethodInvocation *invocation)
 {
        _INFO("_dbus_on_fido_discover");
+
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        if (is_allowed_to_call(invocation, _FIDO_CLIENT_PRIVILEGE) == false) {
 
                __send_discover_response(object, invocation, FIDO_ERROR_PERMISSION_DENIED,
@@ -1352,6 +1375,7 @@ _dbus_on_fido_uaf_is_supported(Fido *object, GDBusMethodInvocation *invocation,
 {
        _INFO("_dbus_on_fido_uaf_is_supported");
 
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        return _dbus_handle_process_or_check_policy(object, invocation, uaf_request_json, NULL,
                                                                                                _PROCESS_TYPE_CHECK_POLICY);
 }
@@ -1362,6 +1386,7 @@ _dbus_on_fido_process_operation(Fido *object, GDBusMethodInvocation *invocation,
 {
        _INFO("_dbus_on_fido_process_operation");
 
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        return _dbus_handle_process_or_check_policy(object, invocation, uaf_request_json,
                                                                                                channel_binding_json, _PROCESS_TYPE_MIN);
 }
@@ -1370,6 +1395,7 @@ _dbus_on_fido_process_operation(Fido *object, GDBusMethodInvocation *invocation,
 _dbus_on_fido_uaf_notify_result(Fido *object, GDBusMethodInvocation *invocation, const gchar *arg_cookie, gint arg_respose_code,
                                                                const gchar *uaf_response_json)
 {
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        fido_complete_fido_uaf_notify_result(object, invocation, 0, 0);
        return true;
 }*/
@@ -1446,7 +1472,32 @@ on_name_lost(GDBusConnection *connection,
 {
                _INFO("on_name_lost");
                _asm_plugin_mgr_destroy();
-               exit(1);
+               exit (1);
+}
+
+
+static gboolean
+__timeout_cb(gpointer user_data)
+{
+       _INFO("__timeout_cb Enter");
+       g_main_loop_quit(mainloop);
+       mainloop = NULL;
+       return false;
+}
+
+static void
+__set_timeout(int seconds)
+{
+       if (seconds < _FIDO_SERVICE_MIN_TIMEOUT) {
+               _ERR("timeout value is wrong");
+               return;
+       }
+
+       if (timeout_handle)
+               g_source_remove(timeout_handle);
+
+       timeout_handle = g_timeout_add_seconds(seconds, __timeout_cb, NULL);
+       _INFO("__set_timeout handle=%d", timeout_handle);
 }
 
 static bool
@@ -1490,8 +1541,6 @@ __initialize(void)
 int
 main(void)
 {
-       GMainLoop *mainloop = NULL;
-
        dlog_print(DLOG_INFO, "FIDO", "start");
 
        _INFO("Starting FIDO SVC");
@@ -1499,6 +1548,7 @@ main(void)
        mainloop = g_main_loop_new(NULL, FALSE);
 
        __initialize();
+       __set_timeout(_FIDO_SERVICE_BOOTUP_TIMEOUT);
 
        g_main_loop_run(mainloop);
        g_main_loop_unref(mainloop);