Module Name:    src
Committed By:   joerg
Date:           Mon Apr 18 03:47:40 UTC 2011

Modified Files:
        src/usr.bin/grep: queue.c

Log Message:
Fix memory leaks.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/grep/queue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/grep/queue.c
diff -u src/usr.bin/grep/queue.c:1.3 src/usr.bin/grep/queue.c:1.4
--- src/usr.bin/grep/queue.c:1.3	Mon Apr 18 03:27:40 2011
+++ src/usr.bin/grep/queue.c	Mon Apr 18 03:47:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $	*/
+/*	$NetBSD: queue.c,v 1.4 2011/04/18 03:47:40 joerg Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/queue.c 211496 2010-08-19 09:28:59Z des $	*/
 /*-
  * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $");
+__RCSID("$NetBSD: queue.c,v 1.4 2011/04/18 03:47:40 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -71,8 +71,11 @@
 
 	STAILQ_INSERT_TAIL(&queue, item, list);
 
-	if (++count > Bflag)
-		free(dequeue());
+	if (++count > Bflag) {
+		item = dequeue();
+		free(item->data.dat);
+		free(item);
+	}
 }
 
 static struct qentry *
@@ -96,6 +99,7 @@
 
 	while ((item = dequeue()) != NULL) {
 		printline(&item->data, '-', (regmatch_t *)NULL, 0);
+		free(item->data.dat);
 		free(item);
 	}
 }
@@ -105,6 +109,8 @@
 {
 	struct qentry *item;
 
-	while ((item = dequeue()) != NULL)
+	while ((item = dequeue()) != NULL) {
+		free(item->data.dat);
 		free(item);
+	}
 }

Reply via email to