On 09/11/10 15:46, Pádraig Brady wrote:
> On 09/11/10 11:02, Blinker| David Hofstee wrote:
>> Hi,
>>
>>
>>
>> When I try to use csplit via stdout from zcat I get the message 'csplit:
>> memory exhausted'. The .gz file is a mysql dump from its databases (one
>> is particularly large):
>
> Yes csplit currently doesn't use a fixed size buffer.
> We need to fix that up.
>
> $ (ulimit -v 100000; yes | ~/git/coreutils/src/csplit - /n/)
> /home/padraig/git/coreutils/src/csplit: memory exhausted
> 23284170
I just looked at the csplit code there,
and it's more sophisticated than I expected.
Therefore it seems this is just a plain old mem leak.
diff --git a/src/csplit.c b/src/csplit.c
index 40baba8..770f891 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, *n;
+ for (l = buf->line_start; l;)
+ {
+ 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;
}