From: Jim Meyering <meyer...@redhat.com> Remove unnecessary and unchecked uses of strdup, and add a comment that this strncpy use is ok.
Signed-off-by: Jim Meyering <meyer...@redhat.com> --- linux-user/elfload.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f3b1552..25175cc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2338,12 +2338,14 @@ static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts) psinfo->pr_uid = getuid(); psinfo->pr_gid = getgid(); - filename = strdup(ts->bprm->filename); - base_filename = strdup(basename(filename)); + filename = ts->bprm->filename; + base_filename = basename(filename); + /* + * Using strncpy here is fine: at max-length, + * this field is not NUL-terminated. + */ (void) strncpy(psinfo->pr_fname, base_filename, sizeof(psinfo->pr_fname)); - free(base_filename); - free(filename); bswap_psinfo(psinfo); return (0); -- 1.7.10.1.487.ga3935e6