Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "Attempt to free unreferenced scalar" errors be safely ignored?

Tags:

perl

I haven't figured out what's causing it, but I'm wondering if there are any consequences to the error (warning?) message "Attempt to free unreferenced scalar: SV 0x825b790 during global destruction". To the untrained eye, it would appear that since the compiler bothered to detect the problem, then it didn't go ahead and re-delete the unreferenced memory.

Is this just telling me that my programming is sloppy? or are there real problems happening that I should be concerned about?

Background: it's not my code, I don't really have time to hunt down the problem, and I should note it's happening right at the end of the program.

like image 421
jk. Avatar asked Jul 07 '14 19:07

jk.


1 Answers

It's a bug in an XS module or in Perl itself. It means there's been a request to deallocate a scalar that has already been deallocated.

This indicates that some code is holding a pointer it thinks is valid, but isn't. This can result in code writing to memory that the code shouldn't be modifying, which can result in data integrity problems, segfaults, etc.

It was detected when the program exits, but the problem happened could have happened at any time. You are subject to problems from the time it was freed until the error was emitted.

For example,

use Inline C => <<'__EOI__';

void buggy(SV* sv) {
   SvREFCNT_dec(sv);
}

__EOI__

my $x;
buggy($x);
# $x is no longer allocated here, but I could still try to use it.

Output:

Attempt to free unreferenced scalar: SV 0xc43fc0, Perl interpreter: 0xc22690.
like image 95
ikegami Avatar answered Oct 16 '22 08:10

ikegami