svace: modified to free memory 54/139454/1
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 19 Jul 2017 04:42:43 +0000 (13:42 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 19 Jul 2017 04:42:43 +0000 (13:42 +0900)
Change-Id: Iafc6c6ba12d483033f96efc2c76a62e9a6c53ed6
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
src/tzplatform_get.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index b37a5eb..1903fe5
@@ -55,10 +55,12 @@ int main(int argc, char **argv)
 {
        char *progname = *argv++, *user = 0;
        int all = 0, not = 0, query = 0, export = 0, space = 0, list = 0, cont = 0;
-       int i, n, *sel, p;
+       int i, n, p;
+       int *sel = NULL;
        enum tzplatform_variable id;
        struct passwd pwd, *spw;
        char buf[1024];
+       int ret = 0;
 
        /* parse args */
        while(*argv && **argv=='-') {
@@ -149,7 +151,7 @@ int main(int argc, char **argv)
 
        /* process */
        n = tzplatform_getcount();
-       sel = calloc( sizeof(int), n);
+       sel = calloc(sizeof(int), n);
        if (sel == NULL) {
                fprintf( stderr, "error! out of memory!\n");
                return 1;
@@ -159,11 +161,15 @@ int main(int argc, char **argv)
        while (*argv) {
                id = tzplatform_getid( *argv);
                if (id == _TZPLATFORM_VARIABLES_INVALID_) {
-                       if (query)
-                               return 1;
+                       if (query) {
+                               ret = 1;
+                               goto out;
+                       }
                        fprintf( stderr, "error! %s isn't a variable.\n", *argv);
-                       if (!cont)
-                               return 1;
+                       if (!cont) {
+                               ret = 1;
+                               goto out;
+                       }
                }
                else {
                        sel[(int)id] = 1;
@@ -172,8 +178,10 @@ int main(int argc, char **argv)
        }
 
        /* finished for queries */
-       if (query) 
-               return 0;
+       if (query) {
+               ret = 0;
+               goto out;
+       }
 
        /* set the user */
        if (user) {
@@ -184,14 +192,18 @@ int main(int argc, char **argv)
                        getpwuid_r((uid_t)atoi(user), &pwd, buf, sizeof(buf), &spw);
                if (!spw) {
                        fprintf( stderr, "error! %s isn't standing for a valid user.\n", user);
-                       if (!cont)
-                               return 1;
+                       if (!cont) {
+                               ret = 1;
+                               goto out;
+                       }
                } else {
                        i = tzplatform_set_user(spw->pw_uid);
                        if (i) {
                                fprintf( stderr, "error! can't set the valid user %s.\n", user);
-                               if (!cont)
-                                       return 1;
+                               if (!cont) {
+                                       ret = 1;
+                                       goto out;
+                               }
                        }
                }
        }
@@ -211,6 +223,13 @@ int main(int argc, char **argv)
        }
        if (p)
                printf("\n");
-       return 0;
+
+       /* return value is 0 */
+       ret = 0;
+out:
+       if (sel)
+               free(sel);
+
+       return ret;
 }