Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Fix a number of memory leaks. Keep final loop of the cleanup...



details:   https://anonhg.NetBSD.org/src/rev/25cdb61bd1e6
branches:  trunk
changeset: 779520:25cdb61bd1e6
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Jun 01 12:08:40 2012 +0000

description:
Fix a number of memory leaks. Keep final loop of the cleanup in tic(1)
under #ifdef __VALGRIND__ though.

diffstat:

 lib/libterminfo/compile.c |   7 ++++---
 usr.bin/tic/tic.c         |  20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 7 deletions(-)

diffs (101 lines):

diff -r 10edd11df563 -r 25cdb61bd1e6 lib/libterminfo/compile.c
--- a/lib/libterminfo/compile.c Fri Jun 01 12:02:36 2012 +0000
+++ b/lib/libterminfo/compile.c Fri Jun 01 12:08:40 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compile.c,v 1.6 2011/11/28 12:44:19 joerg Exp $ */
+/* $NetBSD: compile.c,v 1.7 2012/06/01 12:08:40 joerg Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: compile.c,v 1.6 2011/11/28 12:44:19 joerg Exp $");
+__RCSID("$NetBSD: compile.c,v 1.7 2012/06/01 12:08:40 joerg Exp $");
 
 #if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
 #include <sys/endian.h>
@@ -74,7 +74,7 @@
 
        l = tbuf->bufpos + len;
        if (l > tbuf->buflen) {
-               if (tbuf->bufpos == 0)
+               if (tbuf->buflen == 0)
                        buf = malloc(l);
                else
                        buf = realloc(tbuf->buf, l);
@@ -659,6 +659,7 @@
                free(tic->name);
                free(tic->alias);
                free(tic->desc);
+               free(tic->extras.buf);
                free(tic->flags.buf);
                free(tic->nums.buf);
                free(tic->strs.buf);
diff -r 10edd11df563 -r 25cdb61bd1e6 usr.bin/tic/tic.c
--- a/usr.bin/tic/tic.c Fri Jun 01 12:02:36 2012 +0000
+++ b/usr.bin/tic/tic.c Fri Jun 01 12:08:40 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tic.c,v 1.18 2012/05/31 21:01:06 joerg Exp $ */
+/* $NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: tic.c,v 1.18 2012/05/31 21:01:06 joerg Exp $");
+__RCSID("$NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $");
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -205,6 +205,7 @@
                        }
                        p = e;
                }
+               free(alias);
        }
        
        return 0;
@@ -514,7 +515,7 @@
 
        hcreate(HASH_SIZE);
 
-       buf = NULL;
+       buf = tbuf.buf = NULL;
        buflen = tbuf.buflen = tbuf.bufpos = 0; 
        while ((len = getline(&buf, &buflen, f)) != -1) {
                /* Skip comments */
@@ -539,8 +540,10 @@
                memcpy(tbuf.buf + tbuf.bufpos, buf, len);
                tbuf.bufpos += len;
        }
+       free(buf);
        /* Process the last entry if not done already */
        process_entry(&tbuf, flags);
+       free(tbuf.buf);
 
        /* Merge use entries until we have merged all we can */
        while (merge_use(flags) != 0)
@@ -571,9 +574,18 @@
        if (sflag != 0)
                fprintf(stderr, "%zu entries and %zu aliases written to %s\n",
                    nterm, nalias, p);
-       free(p);
 
+#ifdef __VALGRIND__
+       free(p);
+       while ((term = SLIST_FIRST(&terms)) != NULL) {
+               SLIST_REMOVE_HEAD(&terms, next);
+               _ti_freetic(term->tic);
+               free(term->name);
+               free(term);
+       }
        hdestroy();
+#endif
+
 
        return EXIT_SUCCESS;
 }



Home | Main Index | Thread Index | Old Index