From 0339eb4598600024cedca14a7e882c1737dd2d82 Mon Sep 17 00:00:00 2001 From: Pádraig Brady
Date: Wed, 10 Nov 2010 14:35:17 +0000 Subject: csplit: fix a memory leak per input buffer * src/csplit.c (free_buffer): Also free the line offsets buffers (remove_line): Also free the containing structure * tests/misc/csplit-heap: A new test to trigger with leaks of this magnitude. * tests/Makefile.am: Reference the new test * NEWS: Mention the fix Reported by David Hofstee --- src/csplit.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/csplit.c b/src/csplit.c index 57543f0a2..948a795e2 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -418,6 +418,13 @@ get_new_buffer (size_t min_size) static void free_buffer (struct buffer_record *buf) { + struct line *l; + for (l = buf->line_start; l;) + { + struct line *n = l->next; + free (l); + l = n; + } free (buf->buffer); buf->buffer = NULL; } @@ -542,6 +549,7 @@ remove_line (void) if (prev_buf) { free_buffer (prev_buf); + free (prev_buf); prev_buf = NULL; } -- cgit v1.2.3-70-g09d2