]> granicus.if.org Git - file/commitdiff
fix memory leaks.
authorChristos Zoulas <christos@zoulas.com>
Mon, 27 Sep 2004 15:28:37 +0000 (15:28 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 27 Sep 2004 15:28:37 +0000 (15:28 +0000)
ChangeLog
src/file.c
src/magic.c

index 1239626af45dc42fa845b02f78123888653ec811..9e5ad6e807fca9a7266d6b8e9bc8021b9ab4ede7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-27 11:30  christos Zoulas  <christos@zoulas.com>
+
+       * Remove 3rd and 4th copyright clause; approved by Ian Darwin.
+
+       * Fix small memory leaks; caught by: Tamas Sarlos 
+           <stamas@csillag.ilab.sztaki.hu>
 
 2004-07-24 16:33  Christos Zoulas  <christos@zoulas.com>
 
index 771fdac2e3062125203735d1561adc18d60d30c8..80f5c4108fe34af173ec9cefdac0455dea8605c6 100644 (file)
@@ -72,7 +72,7 @@
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$Id: file.c,v 1.94 2004/09/11 19:15:57 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.95 2004/09/27 15:28:37 christos Exp $")
 #endif /* lint */
 
 
@@ -310,6 +310,7 @@ main(int argc, char *argv[])
                        process(argv[optind], wid);
        }
 
+       magic_close(magic);
        return 0;
 }
 
index 47130c0e44d291127311e90802c220c860dbc01c..4516ba85cf21e1177881b538f8d0d94e3a8aa35a 100644 (file)
@@ -63,7 +63,7 @@
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.23 2004/09/11 19:15:57 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.24 2004/09/27 15:28:37 christos Exp $")
 #endif /* lint */
 
 #ifdef __EMX__
@@ -85,34 +85,34 @@ magic_open(int flags)
                return NULL;
 
        if (magic_setflags(ms, flags) == -1) {
-               free(ms);
                errno = EINVAL;
-               return NULL;
+               goto free1;
        }
 
        ms->o.ptr = ms->o.buf = malloc(ms->o.size = 1024);
-       ms->o.len = 0;
-       if (ms->o.buf == NULL) {
-               free(ms);
-               return NULL;
-       }
+       if (ms->o.buf == NULL)
+               goto free1;
+
        ms->o.pbuf = malloc(ms->o.psize = 1024);
-       if (ms->o.pbuf == NULL) {
-               free(ms->o.buf);
-               free(ms);
-               return NULL;
-       }
+       if (ms->o.pbuf == NULL)
+               goto free2;
+
        ms->c.off = malloc((ms->c.len = 10) * sizeof(*ms->c.off));
-       if (ms->c.off == NULL) {
-               free(ms->o.pbuf);
-               free(ms->o.buf);
-               free(ms);
-               return NULL;
-       }
+       if (ms->c.off == NULL)
+               goto free3;
+       
+       ms->o.len = 0;
        ms->haderr = 0;
        ms->error = -1;
        ms->mlist = NULL;
        return ms;
+free3:
+       free(ms->o.pbuf);
+free2:
+       free(ms->o.buf);
+free1:
+       free(ms);
+       return NULL;
 }
 
 private void
@@ -138,6 +138,7 @@ magic_close(ms)
     struct magic_set *ms;
 {
        free_mlist(ms->mlist);
+       free(ms->o.pbuf);
        free(ms->o.buf);
        free(ms->c.off);
        free(ms);