parrot/parrot — Issue #182: Segfault + seemingly crazy memory gobbling
Author: jnthn
Created: 2011-10-23 17:58:15+00:00
State: open
Labels: bug

This program reliably segfaults for me:

.sub bb
$P0 = new 'ByteBuffer'
$P0 = 100
$I0 = 0
loop:
$I1 = $I0 + 1
$P0[$I0] = $I1
inc $I0
unless $I0 == 100 goto loop
.return ($P0)
.end

.sub main :main
$P0 = new 'ByteBuffer'
$P0 = 1
$P0[0] = 1
$I0 = 0
loop:
$P1 = 'bb'()
$S0 = $P0.'get_string'('binary')
$S1 = $P1.'get_string'('binary')
$S0 = concat $S0, $S1
$P0 = new 'ByteBuffer'
$P0 = $S0
inc $I0
unless $I0 == 10000 goto loop
.end

It does so in the function move_one_buffer in string_gc.c

Also rather worrying is that - even though the longest buffer string it should ever construct is 10000 * 100 bytes (and I guess it segfaults before it gets there) - at the point it segfaults it has eaten 2.7 GB of RAM!