From: Tobias Stoeckmann Date: Sat, 11 Apr 2026 18:51:41 +0000 (+0200) Subject: getopt: Skip optarg duplication X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=5a1fcbc7205cd36d10d25cbc326d03262988f919;p=thirdparty%2Futil-linux.git getopt: Skip optarg duplication The -n argument leaks memory if supplied multiple times. Simplify memory management and reduce binary size. Signed-off-by: Tobias Stoeckmann --- diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index 68dba4597..2bdbb18ec 100644 --- a/misc-utils/getopt.c +++ b/misc-utils/getopt.c @@ -246,7 +246,6 @@ static int generate_output(struct getopt_control *ctl, char *argv[], int argc) free((char *)ctl->long_options[longindex].name); free(ctl->long_options); free(ctl->optstr); - free(ctl->name); return exit_code; } @@ -451,8 +450,7 @@ int main(int argc, char *argv[]) add_long_options(&ctl, optarg); break; case 'n': - free(ctl.name); - ctl.name = xstrdup(optarg); + ctl.name = optarg; break; case 'q': ctl.quiet_errors = 1;