Module Name: src Committed By: joerg Date: Fri Jun 1 12:08:40 UTC 2012
Modified Files: src/lib/libterminfo: compile.c src/usr.bin/tic: tic.c Log Message: Fix a number of memory leaks. Keep final loop of the cleanup in tic(1) under #ifdef __VALGRIND__ though. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libterminfo/compile.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/tic/tic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libterminfo/compile.c diff -u src/lib/libterminfo/compile.c:1.6 src/lib/libterminfo/compile.c:1.7 --- src/lib/libterminfo/compile.c:1.6 Mon Nov 28 12:44:19 2011 +++ src/lib/libterminfo/compile.c Fri Jun 1 12:08:40 2012 @@ -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 @@ _ti_grow_tbuf(TBUF *tbuf, size_t len) 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 @@ _ti_freetic(TIC *tic) 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); Index: src/usr.bin/tic/tic.c diff -u src/usr.bin/tic/tic.c:1.18 src/usr.bin/tic/tic.c:1.19 --- src/usr.bin/tic/tic.c:1.18 Thu May 31 21:01:06 2012 +++ src/usr.bin/tic/tic.c Fri Jun 1 12:08:40 2012 @@ -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 @@ process_entry(TBUF *buf, int flags) } p = e; } + free(alias); } return 0; @@ -514,7 +515,7 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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; }