Fixed to close fd after opening USB node
authorshingil.kang <shingil.kang@samsung.com>
Thu, 4 Jun 2015 06:21:47 +0000 (15:21 +0900)
committershingil.kang <shingil.kang@samsung.com>
Thu, 4 Jun 2015 06:26:15 +0000 (15:26 +0900)
Change-Id: Id4a1fa4be7be033b6a220d2411bb1219f1913741
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
src/usb_linux.c

index e53c0521d1f6675edc7770a94560b47e74772ab4..af8ce4c84354a307d2ba2f2c165a848e62bed3d8 100644 (file)
@@ -123,6 +123,7 @@ int register_device(const char* node, const char* serial) {
     int fd;
     unsigned char device_desc[4096];
     unsigned char* desc_current_ptr = NULL;
+    int is_registered = 0;
 
     if (node == NULL) {
         return -1;
@@ -151,6 +152,7 @@ int register_device(const char* node, const char* serial) {
 
     if (USB_DT_DEVICE_SIZE != usb_dev->bLength) {
         LOG_DEBUG("failed to get usb device descriptor\n");
+        close(fd);
         return -1;
     }
 
@@ -258,6 +260,7 @@ int register_device(const char* node, const char* serial) {
                     usb->node = prepend(&usb_list, usb);
                     LOG_DEBUG("-register new device (in: %04x, out: %04x) from %s\n", usb->end_point[0], usb->end_point[1], node);
 
+                    is_registered = 1;
                     register_usb_transport(usb, usb_serial);
                     sdb_mutex_unlock(&usb_lock, "usb register unlocked");
                 }
@@ -270,6 +273,9 @@ int register_device(const char* node, const char* serial) {
             }
         }
     }
+    if (is_registered == 0) {
+        close(fd);
+    }
     return 0;
 }