magic_test returns a xstrdup'd string, which was then being xstrdup'd
again without freeing the original copy (leaking memory).

casts added to avoid clang warning
      warning: assigning to 'char *' from 'const char *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
                inf->result = s;

ok?

-Bryan.

Index: file/file.c
===================================================================
RCS file: /cvs/src/usr.bin/file/file.c,v
retrieving revision 1.66
diff -u -p -u -r1.66 file.c
--- file/file.c 15 Jan 2018 19:45:51 -0000      1.66
+++ file/file.c 14 Jun 2018 02:55:32 -0000
@@ -603,7 +603,7 @@ try_text(struct input_file *inf)
 
        s = magic_test(inf->m, inf->base, inf->size, flags);
        if (s != NULL) {
-               inf->result = xstrdup(s);
+               inf->result = (char *)s;
                return (1);
        }
 
@@ -635,7 +635,7 @@ try_magic(struct input_file *inf)
 
        s = magic_test(inf->m, inf->base, inf->size, flags);
        if (s != NULL) {
-               inf->result = xstrdup(s);
+               inf->result = (char *)s;
                return (1);
        }
        return (0);

Reply via email to