[Israel.pm] Unreference file scalar

Shmuel Fomberg semuelf at 012.net.il
Wed Sep 19 11:12:08 PDT 2007

Hello There.

For a long time I had an annoying error at the end of my embedded program:
Attempt to free unreferenced scalar: SV 0x2391848 during global destruction.

Now I tracked it's source. In the beginning of my program, I eval (using
eval_sv) the following lines:
   open my $fh, ">>", 'filename.txt' or die 'Failed to redirect';
   select $fh;
It's for redirecting the stdout of the Perl part to a log file, so it won't
write to the screen. (plus, it's convenient)
And that caused the error. Perl kept this $fh alive because it is selected,
but its reference count get decreased to zero. 
And when it's time for global destruction, Perl finds this file and discover
that it has zero references. 

This is probably a bug, but I can not reproduce it in pure-perl, (without
embedding) so - oh well.


More information about the Perl mailing list