From: Dmitry V. Levin Date: Thu, 20 Jul 2017 22:55:57 +0000 (+0000) Subject: Do not copy optarg unnecessarily X-Git-Tag: v4.19~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30861c93214841cfb1da21e2f1954adbca1d272a;p=strace Do not copy optarg unnecessarily There is no need to copy the optarg string since it is a pointer into the original argv array, not into a static area that might be overwritten. * strace.c (username, outfname): Add const qualifier. (init): Do not xstrdup optarg to initialize outfname and username. --- diff --git a/strace.c b/strace.c index 955a1c9f..c503c3d1 100644 --- a/strace.c +++ b/strace.c @@ -134,7 +134,7 @@ static int exit_code; static int strace_child; static int strace_tracer_pid; -static char *username; +static const char *username; static uid_t run_uid; static gid_t run_gid; @@ -142,7 +142,7 @@ unsigned int max_strlen = DEFAULT_STRLEN; static int acolumn = DEFAULT_ACOLUMN; static char *acolumn_spaces; -static char *outfname; +static const char *outfname; /* If -ff, points to stderr. Else, it's our common output log */ static FILE *shared_log; @@ -1727,7 +1727,7 @@ init(int argc, char *argv[]) qualify(optarg); break; case 'o': - outfname = xstrdup(optarg); + outfname = optarg; break; case 'O': i = string_to_uint(optarg); @@ -1751,7 +1751,7 @@ init(int argc, char *argv[]) set_sortby(optarg); break; case 'u': - username = xstrdup(optarg); + username = optarg; break; #ifdef USE_LIBUNWIND case 'k':