]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: Skip optarg duplication
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 11 Apr 2026 18:35:56 +0000 (20:35 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 12 Apr 2026 10:37:04 +0000 (12:37 +0200)
The -f arguments are collected in files array, which contains strings
which are used for opening files and error messages. Remove duplication
which simplifies memory handling and reduces binary size.

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

index 0afdf9dd4e647da884437c7056b145207f31eae2..e953a021427dd8c716caf7d5f2b972110f15292d 100644 (file)
@@ -994,7 +994,7 @@ int main(int argc, char **argv)
                .domain_len = LAST_DOMAIN_LEN,
                .fullnames_mode = false,
        };
-       char **files = NULL;
+       const char **files = NULL;
        struct number_buffer nb = {
                .pos = 0
        };
@@ -1065,7 +1065,7 @@ int main(int argc, char **argv)
                case 'f':
                        if (!files)
                                files = xmalloc(sizeof(char *) * argc);
-                       files[nfiles++] = xstrdup(optarg);
+                       files[nfiles++] = optarg;
                        break;
                case 'd':
                        ctl.usedns = 1;
@@ -1133,13 +1133,12 @@ int main(int argc, char **argv)
 
        if (!files) {
                files = xmalloc(sizeof(char *));
-               files[nfiles++] = xstrdup(ctl.lastb ? _PATH_BTMP : _PATH_WTMP);
+               files[nfiles++] = ctl.lastb ? _PATH_BTMP : _PATH_WTMP;
        }
 
        for (i = 0; i < nfiles; i++) {
                get_boot_time(&ctl.boot_time);
                process_wtmp_file(&ctl, files[i]);
-               free(files[i]);
        }
        free(files);
        return EXIT_SUCCESS;