Dave Howorth has asked for the wisdom of the Perl Monks concerning the following question:

One of my programs started giving me this error this morning. Mondays, don't ya just luv em?

It's a complicated program and I'd made some changes but none in the part of the program that's crashing. And I don't think any of my code does anything that's likely to provoke this kind of behaviour. I've added some debug statements at the point of failure and this stanza:

$swiss = 'P07445'; warn "swiss='$swiss'\n"; my @rer; $rer[0] = $swiss =~ /^\p{IsAlpha}/;

produces:

swiss='P07445' panic: Something requested a negative number of bytes of malloc.

but only if I run it in the debugger. If I let the program run freestanding, it works. Sadly my original program crashes if I let it run.

Has anybody seen this problem before or have any ideas how to debug it? Presumably something is stamping on memory somewhere but what? I'm using perl 5.8.6

Thanks, Dave

Replies are listed 'Best First'.
Re: panic: Something requested a negative number of bytes of malloc
by moritz (Cardinal) on Nov 05, 2007 at 14:05 UTC
    I can't reproduce this problem. I tried with perl 5.8.8 and 5.10.0 with this script:

    #!/usr/bin/perl use strict; use warnings; my $swiss = 'P07445'; warn "swiss='$swiss'\n"; my @rer; $rer[0] = $swiss =~ /^\p{IsAlpha}/;

    Most likely some XS or Inline::C module (or an interpreter bug) corrupts your program's memory, and then it dies at an otherwise harmless operation.

    Please try to reproduce the problem with a minimal but complete example (i.e. it crashes, but uses as little modules and code as possible) - I don't think the example you gave us crashes on your perl, unless it's executed in the context of another program.

Re: panic: Something requested a negative number of bytes of malloc
by graff (Chancellor) on Nov 06, 2007 at 03:36 UTC
    As moritz suggests, it's likely that recent versions of perl have fixed this problem, but I know from experience with some of the steps between 5.8.0 and 5.8.7 that unicode stuff tends to break the debugger. It's a severe drag: code that works fine just runs, and code that has a problem works fine except for whatever the problem is, so long as you don't run it with "perl -d".

    The "\p{...}" operator in the regex is invoking unicode processing, and for reasons I don't understand, it's doing so in a way that is lethal to the debugger. I'm pretty sure the worst of the trouble is gone from 5.8.8, though I'm not sure 5.8.8 solves all the problems. I haven't had a chance to play with 5.8.10 yet.