Skip to content

Commit

Permalink
perf(dracut-install): don't strdup() environment block
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli authored and aafeijoo-suse committed Dec 28, 2022
1 parent 77226cb commit efd4ca2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/install/dracut-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,10 @@ static int parse_argv(int argc, char *argv[])
arg_module = true;
break;
case 'D':
destrootdir = strdup(optarg);
destrootdir = optarg;
break;
case 'r':
sysrootdir = strdup(optarg);
sysrootdir = optarg;
sysrootdirlen = strlen(sysrootdir);
break;
case 'p':
Expand Down Expand Up @@ -1115,10 +1115,10 @@ static int parse_argv(int argc, char *argv[])
arg_mod_filter_noname = true;
break;
case 'L':
logdir = strdup(optarg);
logdir = optarg;
break;
case ARG_KERNELDIR:
kerneldir = strdup(optarg);
kerneldir = optarg;
break;
case ARG_FIRMWAREDIRS:
firmwaredirs = strv_split(optarg, ":");
Expand Down Expand Up @@ -2012,7 +2012,6 @@ int main(int argc, char **argv)
log_error("Environment DESTROOTDIR or argument -D is not set!");
usage(EXIT_FAILURE);
}
destrootdir = strdup(destrootdir);
}

if (strcmp(destrootdir, "/") == 0) {
Expand All @@ -2021,21 +2020,19 @@ int main(int argc, char **argv)
}

i = destrootdir;
destrootdir = realpath(destrootdir, NULL);
if (!destrootdir) {
if (!(destrootdir = realpath(i, NULL))) {
log_error("Environment DESTROOTDIR or argument -D is set to '%s': %m", i);
r = EXIT_FAILURE;
goto finish;
goto finish2;
}
free(i);

items = hashmap_new(string_hash_func, string_compare_func);
items_failed = hashmap_new(string_hash_func, string_compare_func);

if (!items || !items_failed || !modules_loaded) {
log_error("Out of memory");
r = EXIT_FAILURE;
goto finish;
goto finish1;
}

if (logdir) {
Expand All @@ -2045,7 +2042,7 @@ int main(int argc, char **argv)
if (logfile_f == NULL) {
log_error("Could not open %s for logging: %m", logfile);
r = EXIT_FAILURE;
goto finish;
goto finish1;
}
}

Expand Down Expand Up @@ -2078,7 +2075,9 @@ int main(int argc, char **argv)
if (arg_optional)
r = EXIT_SUCCESS;

finish:
finish1:
free(destrootdir);
finish2:
if (logfile_f)
fclose(logfile_f);

Expand All @@ -2095,7 +2094,6 @@ int main(int argc, char **argv)
hashmap_free(items_failed);
hashmap_free(modules_loaded);

free(destrootdir);
strv_free(firmwaredirs);
strv_free(pathdirs);
return r;
Expand Down

0 comments on commit efd4ca2

Please sign in to comment.