]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
getopt: Skip optarg duplication
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 11 Apr 2026 18:51:41 +0000 (20:51 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 12 Apr 2026 11:08:38 +0000 (13:08 +0200)
The -n argument leaks memory if supplied multiple times. Simplify memory
management and reduce binary size.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
misc-utils/getopt.c

index 68dba4597e382f38d7db7a9c246db7ed3c9ccc5f..2bdbb18ec1db1e914b0a3067264f6cdf62d9deda 100644 (file)
@@ -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;