Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix memory leak (Anatol Belski)

  • Loading branch information...
commit c0c0032b9e9eb57b91fefef905a3b018bab492d9 1 parent dcfaba6
@zoulasc zoulasc authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/softmagic.c
View
12 src/softmagic.c
@@ -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"
@@ -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);

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;
@glensc Owner
glensc added a note

@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.

@zoulasc
zoulasc added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return rv;
case FILE_USE:
@remicollet

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;
@glensc

@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.

@zoulasc
Please sign in to comment.
Something went wrong with that request. Please try again.