Skip to content

Commit

Permalink
Fix memory leak (Anatol Belski)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoulasc committed Feb 21, 2014
1 parent dcfaba6 commit c0c0032
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/softmagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$File: softmagic.c,v 1.175 2014/02/18 11:09:31 kim Exp $")
FILE_RCSID("@(#)$File: softmagic.c,v 1.176 2014/02/18 17:59:21 kim Exp $")
#endif /* lint */

#include "magic.h"
Expand Down Expand Up @@ -1762,12 +1762,16 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
ms->offset = soffset;
if (rv == 1) {
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
file_printf(ms, F(m->desc, "%u"), offset) == -1)
file_printf(ms, F(m->desc, "%u"), offset) == -1) {
free(rbuf);
return -1;
if (file_printf(ms, "%s", rbuf) == -1)
}
if (file_printf(ms, "%s", rbuf) == -1) {
free(rbuf);
return -1;
free(rbuf);
}
}
free(rbuf);

This comment has been minimized.

Copy link
@remicollet

remicollet Feb 26, 2014

I observe, in some run condition, than rbuf could be NULL, so this could raise a minor issue.
The path applied in PHP seems to work correctly with

    if (rbuf) {
        free(rbuf);
    }

Ok, free(NULL) is valid.

Would it be simpler to use:

    if (rv == 1) {
        if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
              file_printf(ms, m->desc, offset) == -1) {
            rv = -1;
        }
        else if (file_printf(ms, "%s", rbuf) == -1) {
            rv = -1;
        }
    }
    if (rbuf) {
        free(rbuf);
    }
    return rv;

This comment has been minimized.

Copy link
@glensc

glensc Feb 26, 2014

Member

@remicollet please read this mirror description:

NOTE: do not make pull requests here, nor comment any commits, submit them usual way to bug tracker or to the mailing list. Maintainer(s) are not tracking this git mirror.

This comment has been minimized.

Copy link
@zoulasc

zoulasc via email Feb 26, 2014

Author Contributor
return rv;

case FILE_USE:
Expand Down

0 comments on commit c0c0032

Please sign in to comment.