prevent: fixed ecs related prevent issues 03/11103/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 18 Oct 2013 06:34:40 +0000 (15:34 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 18 Oct 2013 06:34:40 +0000 (15:34 +0900)
Change-Id: I180b1a7c2600576968ab98b9939c8e3b24142c1d
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs_msg.c
tizen/src/guest_server.c
tizen/src/hw/maru_virtio_sensor.c

index 1a2a1a2d32b339ce54aa2aa478659a37201e50ef..3902236b93d7e156206c701174a26f234cd63c66 100644 (file)
@@ -69,6 +69,8 @@ static int payloadsize;
 static int port;
 static int port_setting = -1;
 
+static int log_fd = -1;
+
 static pthread_mutex_t mutex_clilist = PTHREAD_MUTEX_INITIALIZER;
 
 static char* get_emulator_ecs_log_path(void)
@@ -125,18 +127,28 @@ static inline void start_logging(void) {
     stdout[0] = flog[0];
     stderr[0] = flog[0];
 #else
-    int fd = open("/dev/null", O_RDONLY);
-    dup2(fd, 0);
+    log_fd = open("/dev/null", O_RDONLY);
+    dup2(log_fd, 0);
 
-    fd = creat(path, 0640);
-    if (fd < 0) {
-        fd = open("/dev/null", O_WRONLY);
+    log_fd = creat(path, 0640);
+    if (log_fd < 0) {
+        log_fd = open("/dev/null", O_WRONLY);
     }
-    dup2(fd, 1);
-    dup2(fd, 2);
+    dup2(log_fd, 1);
+    dup2(log_fd, 2);
 #endif
 }
 
+static inline void stop_logging(void) {
+    int ret = -1;
+    if (log_fd >= 0) {
+        ret = close(log_fd);
+        if (ret != 0) {
+            LOG("failed to close log fd.");
+        }
+    }
+}
+
 int ecs_write(int fd, const uint8_t *buf, int len) {
     LOG("write buflen : %d, buf : %s", len, (char*)buf);
     if (fd < 0) {
@@ -147,9 +159,12 @@ int ecs_write(int fd, const uint8_t *buf, int len) {
 }
 
 void ecs_client_close(ECS_Client* clii) {
+    if (clii == NULL)
+        return;
+
     pthread_mutex_lock(&mutex_clilist);
 
-    if (0 <= clii->client_fd) {
+    if (clii->client_fd > 0) {
         LOG("ecs client closed with fd: %d", clii->client_fd);
         closesocket(clii->client_fd);
 #ifndef CONFIG_LINUX
@@ -159,10 +174,9 @@ void ecs_client_close(ECS_Client* clii) {
     }
 
     QTAILQ_REMOVE(&clients, clii, next);
-    if (NULL != clii) {
-        g_free(clii);
-        clii = NULL;
-    }
+
+    g_free(clii);
+    clii = NULL;
 
     pthread_mutex_unlock(&mutex_clilist);
 }
@@ -243,13 +257,16 @@ static void ecs_close(ECS_State *cs) {
     ECS_Client *clii;
     LOG("### Good bye! ECS ###");
 
+    if (cs == NULL)
+        return;
+
     if (0 <= cs->listen_fd) {
         LOG("close listen_fd: %d", cs->listen_fd);
         closesocket(cs->listen_fd);
         cs->listen_fd = -1;
     }
 
-    if (NULL != cs->mon) {
+    if (cs->mon != NULL) {
         g_free(cs->mon);
         cs->mon = NULL;
     }
@@ -258,7 +275,7 @@ static void ecs_close(ECS_State *cs) {
         g_free(keepalive_buf);
     }
 
-    if (NULL != cs->alive_timer) {
+    if (cs->alive_timer != NULL) {
         qemu_del_timer(cs->alive_timer);
         cs->alive_timer = NULL;
     }
@@ -268,10 +285,11 @@ static void ecs_close(ECS_State *cs) {
         ecs_client_close(clii);
     }
 
-    if (NULL != cs) {
-        g_free(cs);
-        cs = NULL;
-    }
+    g_free(cs);
+    cs = NULL;
+    current_ecs = NULL;
+
+    stop_logging();
 }
 
 #ifndef _WIN32
@@ -555,6 +573,11 @@ static void alive_checker(void *opaque) {
         send_keep_alive_msg(clii);
     }
 
+    if (current_ecs == NULL) {
+        LOG("alive checking is failed because current ecs is null.");
+        return;
+    }
+
     qemu_mod_timer(current_ecs->alive_timer,
             qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() * TIMER_ALIVE_S);
 
@@ -839,7 +862,7 @@ bool handle_protobuf_msg(ECS_Client* cli, char* data, int len)
         if (!msg)
             goto fail;
         msgproc_nfc_req(cli, msg);
-       }
+    }
 #if 0
     else if (master->type == ECS__MASTER__TYPE__CHECKVERSION_REQ)
     {
index 2f1b095c6c088b2cfa2beedf129d0c3efcb1a8d9..4dbd3c4d6ec6f17e09ff2506a95f67f4875a38a1 100644 (file)
@@ -272,7 +272,9 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
                 get_sensor_proxi();
             }
         } else {
-            set_sensor_data(length, data);
+            if (data != NULL) {
+                set_sensor_data(length, data);
+            }
         }
     } else if (!strncmp(cmd, "Network", 7)) {
         LOG(">>> Network msg: '%s'", data);
@@ -321,7 +323,9 @@ bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg)
     }
 
     if (!strncmp(cmd, MSG_TYPE_NFC, 3)) {
-        send_to_nfc(request_nfc_set, data, msg->data.len);
+        if (data != NULL) {
+            send_to_nfc(request_nfc_set, data, msg->data.len);
+        }
     }
 
     return true;
@@ -344,7 +348,7 @@ bool ntf_to_injector(const char* data, const int len) {
 
     const char* ijdata = (data + catsize + 2 + 1 + 1);
 
-    char *encoded_ijdata = NULL;
+    const char *encoded_ijdata = "";
      LOG("<< header cat = %s, length = %d, action=%d, group=%d", cat, length,
             action, group);
 
index 0c44bc46c96cf5838edf070ce9d20d1572dadc8d..72782d8b86664f2cca95265c5ef779eca1a5e111 100644 (file)
@@ -106,12 +106,14 @@ static void add_sdb_client(const char* addr, int port)
 
 static void remove_sdb_client(GS_Client* client)
 {
+    if (client == NULL) {
+        return;
+    }
+
     pthread_mutex_lock(&mutex_clilist);
 
     QTAILQ_REMOVE(&clients, client, next);
-    if (NULL != client) {
-        g_free(client);
-    }
+    g_free(client);
 
     pthread_mutex_unlock(&mutex_clilist);
 }
@@ -308,6 +310,7 @@ gchar *get_tizen_sdk_data_path(void)
 
             INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path);
 
+            fclose(sdk_info_fp);
             return tizen_sdk_data_path;
         }
 
index a89272da3af566669513a64bf3f87f574345a9f3..4558225315cb0fae7d36de3044f7666c14105084 100644 (file)
@@ -85,6 +85,7 @@ void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data,
     if (req == request_set) {
         if (len > _MAX_BUF) {
             ERR("The data is too big to send.\n");
+                       free(msg);
             return;
         }
         memcpy(msg->buf, data, len);