[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#7357: csplit: memory exhausted when using stdout / pipe instead of a

From: Jim Meyering
Subject: bug#7357: csplit: memory exhausted when using stdout / pipe instead of a file
Date: Wed, 10 Nov 2010 18:27:29 +0100

Pádraig Brady wrote:
> I'll apply this patch in a few hours,
> and it will be in the very soon to be released
> coreutils 8.7
> Subject: [PATCH] csplit: fix a memory leak
> * 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

Thanks for working on that.

It's slightly better to move the "n" into the scope where used.
2 reasons:
  - tighter scoping is always better
  - more readable not to put two variable decls on the same line

> +  for (l = buf->line_start; l;)
> +    {
> +      n = l->next;
> +      free (l);
> +      l = n;
> +    }
>    free (buf->buffer);
>    buf->buffer = NULL;
>  }

> diff --git a/tests/Makefile.am b/tests/Makefile.am
> diff --git a/tests/misc/csplit-heap b/tests/misc/csplit-heap
> +(
> + ulimit -v 20000
> + { yes | head -n2500000; echo n; } | csplit -z - %n%1
> +) || fail=1

That looks fine except that there were some problems
(sorry, don't remember details off hand)
with tests using that "yes|..." idiom, so I converted
them all to use other means.

I don't particularly like the performance hit you get with

    awk 'BEGIN { for(i=0;i<2500000;i++) print "y"; print "n" }'

Using yes as you did above is nearly 10x faster.
But at least it's portable.

Even with perl, it's still a factor of 2x:

    perl -e 'print "y\n" x 2500000, "n\n"'

which would be ok, but perl is nominally less portable than awk.
As far as I'm concerned, using require-perl is fine.
Take your pick, or even leave it using yes|head for now.
It's no big deal if the test fails on some fringe system.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]