[Title] fix prevent defects on lib/libcommon/fileio.c, safestring.c
authorSooyoung Ha <yoosah.ha@samsung.com>
Thu, 10 Jan 2013 02:47:07 +0000 (11:47 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Thu, 10 Jan 2013 02:47:07 +0000 (11:47 +0900)
[Desc.] Resource leak and null check (regression on safestring.c)
[Issue] Prevent CID 38197~8, 33895~8

lib/libcommon/fileio.c
lib/libcommon/safestring.c

index 98dbc2e2a83e48ba7507f4bf884e31f511b9ba95..30930b612ba0a50c5cc1f3cb12d6268bc3331d1f 100644 (file)
@@ -148,6 +148,7 @@ gchar *get_kernel_path(void)
        gchar *kernel_path = NULL;
        kernel_path = (char *)malloc( 512);
        if(kernel_path == NULL){
+           g_free(path);
            return NULL;
        }
        memset(kernel_path, 0, 512);
@@ -204,6 +205,7 @@ gchar *get_conf_path(void)
        gchar *path = NULL;
        path = get_path();
        if(path == NULL){
+           g_free(conf_path);
            return NULL;
        }
 
index 212ef7f7f6386ca944011891821e75afa9a1e9aa..b78bfb79898a67431bb676e3c0f397964f3d62f5 100644 (file)
@@ -89,13 +89,13 @@ gsize s_strcmp(const char *dst, const char *src)
        int srcsize;
        int dstsize;
 
-       srcsize = strlen(src);
-       dstsize = strlen(dst);
-
        if (!dst || !src) {
                return -1;
        }
 
+       srcsize = strlen(src);
+       dstsize = strlen(dst);
+
        if ((srcsize == 0) && (dstsize == 0)) {
                return 0;
        }
@@ -126,13 +126,13 @@ gsize s_strncmp(const char *dst, const char *src, int n)
        int srcsize;
        int dstsize;
 
-       srcsize = strlen(src);
-       dstsize = strlen(dst);
-
        if (!dst || !src) {
                return -1;
        }
 
+       srcsize = strlen(src);
+       dstsize = strlen(dst);
+
        if ((srcsize == 0) && (dstsize == 0)) {
                return 0;
        }