On Thu, Jun 14, 2018 at 08:18:22AM +0100, Nicholas Marriott wrote:
> I think this is better?
That works too.
ok brynet@
> Index: magic-test.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/file/magic-test.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 magic-test.c
> --- magic-test.c 18 Apr 2017 14:16:48 -0000 1.25
> +++ magic-test.c 14 Jun 2018 07:16:41 -0000
> @@ -1404,10 +1404,10 @@ magic_test(struct magic *m, const void *
> if (*ms.out != '\0') {
> if (flags & MAGIC_TEST_MIME) {
> if (ms.mimetype != NULL)
> - return (xstrdup(ms.mimetype));
> + return (ms.mimetype);
> return (NULL);
> }
> - return (xstrdup(ms.out));
> + return (ms.out);
> }
> return (NULL);
> }
>
>
>
> On Wed, Jun 13, 2018 at 11:00:58PM -0400, Bryan Steele wrote:
> > 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);
> >
>