Commit Diff


commit - 5a7ffad52579ed044585975028c64964df203f35
commit + 755142eaf116858c71b8f3838057537739289e5a
blob - 1762aa72057da2e6aa98f42cd006df84bf163c24
blob + 157aa9576a89e6901e92e364843261452ef73b6b
--- lib/diffreg.c
+++ lib/diffreg.c
@@ -983,7 +983,6 @@ restart:
 	if (args->diff_format != D_IFDEF && a > b && c > d)
 		return (0);
 	if (args->ignore_pats != NULL) {
-		char *line;
 		/*
 		 * All lines in the change, insert, or delete must
 		 * match an ignore pattern for the change to be
@@ -991,24 +990,30 @@ restart:
 		 */
 		if (a <= b) {		/* Changes and deletes. */
 			for (i = a; i <= b; i++) {
-				line = preadline(fileno(f1),
+				char *line = preadline(fileno(f1),
 				    ds->ixold[i] - ds->ixold[i - 1],
 				    ds->ixold[i - 1]);
 				if (line == NULL)
 					return (-1);
-				if (!ignoreline(line))
+				if (!ignoreline(line)) {
+					free(line);
 					goto proceed;
+				}
+				free(line);
 			}
 		}
 		if (a > b || c <= d) {	/* Changes and inserts. */
 			for (i = c; i <= d; i++) {
-				line = preadline(fileno(f2),
+				char *line = preadline(fileno(f2),
 				    ds->ixnew[i] - ds->ixnew[i - 1],
 				    ds->ixnew[i - 1]);
 				if (line == NULL)
 					return (-1);
-				if (!ignoreline(line))
+				if (!ignoreline(line)) {
+					free(line);
 					goto proceed;
+				}
+				free(line);
 			}
 		}
 		return (0);