summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep/grep.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-07-17 15:48:11 +0000
committerpfg <pfg@FreeBSD.org>2014-07-17 15:48:11 +0000
commit642f571df9c895495cfc45b7c0c119609e561184 (patch)
tree6d149a7ff25f31c914800f385a1ac346e1f9bd6e /usr.bin/grep/grep.c
parentbcd1a4acd05f39f35ed9d7dd88c24cd1bb0d0cff (diff)
downloadFreeBSD-src-642f571df9c895495cfc45b7c0c119609e561184.zip
FreeBSD-src-642f571df9c895495cfc45b7c0c119609e561184.tar.gz
grep: fix some memory leaks.
Bring a couple of changes from NetBSD: queue.c (CVS Rev. 1.4. 1.5) Fix memory leaks. NULL does not need a cast. grep.c (CVS Rev. 1.6) Use the more portable getline. Obtained from: NetBSD MFC after: 3 days
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r--usr.bin/grep/grep.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 74446b6..5631877 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: grep.c,v 1.4 2011/02/16 01:31:33 joerg Exp $ */
+/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */
/* $FreeBSD$ */
/* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <libgen.h>
#include <locale.h>
#include <stdbool.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -304,6 +305,7 @@ read_patterns(const char *fn)
FILE *f;
char *line;
size_t len;
+ ssize_t rlen;
if ((f = fopen(fn, "r")) == NULL)
err(2, "%s", fn);
@@ -311,8 +313,11 @@ read_patterns(const char *fn)
fclose(f);
return;
}
- while ((line = fgetln(f, &len)) != NULL)
+ len = 0;
+ line = NULL;
+ while ((rlen = getline(&line, &len, f)) != -1)
add_pattern(line, line[0] == '\n' ? 0 : len);
+ free(line);
if (ferror(f))
err(2, "%s", fn);
fclose(f);
OpenPOWER on IntegriCloud