tethering: improve error cases. 56/25556/2
authorKitae Kim <kt920.kim@samsung.com>
Thu, 7 Aug 2014 04:56:21 +0000 (13:56 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 7 Aug 2014 06:51:56 +0000 (23:51 -0700)
 - null pointer dereferences
 - control flow issues
 - integer handling issues

Change-Id: I9338e0997f86f62e014df972404320277c42a31b
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/tethering/common.c
tizen/src/tethering/encode_fb.c

index 6e11e765d5aa6ad59f528b288498b2d4c1629ab6..a17c9418d1f2c8876650033a520f49d07b955f4e 100644 (file)
@@ -162,6 +162,7 @@ bool send_msg_to_controller(void *msg)
             if (errno == EAGAIN) {
                 fd_set writefds;
                 struct timeval timeout;
+                int result = 0;
 
                 FD_ZERO(&writefds);
                 FD_SET(sockfd, &writefds);
@@ -169,9 +170,10 @@ bool send_msg_to_controller(void *msg)
                 timeout.tv_sec = 1;
                 timeout.tv_usec = 0;
 
-                ret = select(sockfd + 1, NULL, &writefds, NULL, &timeout);
-                if (ret < 0) {
+                result = select(sockfd + 1, NULL, &writefds, NULL, &timeout);
+                if (result < 0) {
                     LOG_INFO("not possible to send data\n");
+                    ret = false;
                     break;
                 }
                 LOG_TRACE("possible to send data\n");
@@ -634,7 +636,7 @@ static int start_tethering_socket(const char *ipaddress, int port)
         }
     }
 
-    if (ret < 0 && ret != -EISCONN) {
+    if (ret < 0) {
         if (ret == -ECONNREFUSED) {
             LOG_INFO("socket connection is refused\n");
             set_tethering_connection_status(CONNREFUSED);
index 8f4f71709a551681c445250408db8123a8a694fc..139fcb195996edb1c76d4ea0df752b9327865042 100644 (file)
@@ -104,10 +104,10 @@ static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t len)
 
     if (!p->buffer) {
         LOG_SEVERE("failed to allocate \n");
+    } else {
+        memcpy(p->buffer + p->length, data, len);
+        p->length += len;
     }
-
-    memcpy(p->buffer + p->length, data, len);
-    p->length += len;
 }
 
 static void user_flush_data(png_structp png_ptr)
@@ -162,7 +162,7 @@ static void *encode_png(void)
 
     LOG_TRACE("png_create_info_struct\n");
     info_ptr = png_create_info_struct(png_ptr);
-    if (!png_ptr) {
+    if (!info_ptr) {
         LOG_SEVERE("png_create_info_struct failure\n");
         g_free(surface);
         png_destroy_write_struct(&png_ptr, &info_ptr);