[Prevent] fix Tizen 36515,36516,37705 - STRING_OVERFLOW, RESOURCE_LEAK
authorjaehoon.you <jaehoon.you@samsung.com>
Tue, 8 Jan 2013 11:37:24 +0000 (20:37 +0900)
committerjaehoon.you <jaehoon.you@samsung.com>
Tue, 8 Jan 2013 11:37:24 +0000 (20:37 +0900)
Change-Id: I184458fd8419d4e32a9a493f2258dbbdd2637980
Signed-off-by: jaehoon.you <jaehoon.you@samsung.com>
lthor.c

diff --git a/lthor.c b/lthor.c
index c0dbbf456cf05b15ece1539237d7f258faec0377..e9419f04b46f7f86fcd472cb676196f4549a52da 100755 (executable)
--- a/lthor.c
+++ b/lthor.c
@@ -445,7 +445,7 @@ const char* find_usb_device(void)
        char buffer[11];
        const char *dirname = "/sys/bus/usb/devices";
        char usbpath[0x400];
-       char usbdir[0x40];
+       char usbdir[0x100];
        char *tty = NULL;
 
        d = opendir(dirname);
@@ -583,6 +583,7 @@ int open_port(const char *portname, int wait)
        r = tcgetattr(fd, &tios);
        if (r < 0) {
                fprintf(stderr, "line %d: tcgetattr failed\n", __LINE__);
+               close(fd);
                return -1;
        }
 
@@ -595,18 +596,21 @@ int open_port(const char *portname, int wait)
        r = tcsetattr(fd, TCSANOW, &tios);
        if (r < 0) {
                fprintf(stderr, "line %d: tcsetattr failed\n", __LINE__);
+               close(fd);
                return -1;
        }
 
        r = tcflush(fd, TCIOFLUSH);
        if (r < 0) {
                fprintf(stderr, "line %d: tcflush failed\n", __LINE__);
+               close(fd);
                return -1;
        }
 
        r = thor_handshake(fd);
        if (r < 0) {
                fprintf(stderr, "line %d: handshake failed\n", __LINE__);
+               close(fd);
                return -1;
        }
 
@@ -942,6 +946,7 @@ int process_download(const char *portname, const char *pitfile, char **tarfileli
                printf("\x1b[0;33;1m%s :\x1b[0m\n", *tfl);
                if (get_entry_size_in_tar(*tfl, &len) < 0) {
                        perror("Error");
+                       close(fd);
                        return -1;
                }
                total += len;
@@ -953,6 +958,7 @@ int process_download(const char *portname, const char *pitfile, char **tarfileli
                if (pit_length < 0) {
                        fprintf(stderr, "line %d: failed to get pit length\n"
                                , __LINE__);
+                       close(fd);
                        return -1;
                }
                total += pit_length;
@@ -970,6 +976,7 @@ int process_download(const char *portname, const char *pitfile, char **tarfileli
         */
        if (r) {
                fprintf(stderr, "RQT_DL_INIT, status = %08x\n", r);
+               close(fd);
                return -1;
        }