{
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=='-') {
/* 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;
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;
}
/* finished for queries */
- if (query)
- return 0;
+ if (query) {
+ ret = 0;
+ goto out;
+ }
/* set the user */
if (user) {
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;
+ }
}
}
}
}
if (p)
printf("\n");
- return 0;
+
+ /* return value is 0 */
+ ret = 0;
+out:
+ if (sel)
+ free(sel);
+
+ return ret;
}