Executive summary: a program that was working, broke, and I fixed it. The trail that led to the resolution of the problem is, IMHO, worth studying.

I upgraded FreeBSD on a server the other day, from 4.9-PRERELEASE to 5.2-RELEASE. I compiled perl 5.8.3 with 100% regression test success and installed it under /usr/local (the default perl continues to live in /usr). This morning I noticed that a script that worked correctly before is now spewing the following error:

Attempt to free unreferenced scalar: SV 0x849856c at /usr/local/lib/perl5/5.8.3/i386-freebsd/IO/Socket.pm line 137.

I isolated the problem down to the following routine. It's in a child process that is simply checking to see whether something is listening on a remote port:

sub _listening { my $s = IO::Socket::INET->new( Timeout => TIMEOUT, PeerHost => $_[0], Proto => $_[1], PeerPort => $_[2] ) or return 0; close $s; return 1; }

Commenting out the IO::Socket::INET constructor and just returning 1 made the problem go away... So, what to do?

Figuring that my $foo = thing() or return might be considered too unclean these days, I rewrote it as follows:

sub _listening { my $ok = 0; my $s = IO::Socket::INET->new( Timeout => TIMEOUT, PeerHost => $_[0], Proto => $_[1], PeerPort => $_[2] ); if( $s ) { close $s; $ok = 1; } return $ok; }

... the error messages, however, continued. I checked with CPAN, the IO::Socket and IO::Socket::INET modules are up to date (I would have been really surprised if they weren't, but it was a cheap test). I had a look at the module. The reported line is in the connect routine, at the line

$sock->blocking(1) if $blocking;

I starting searching on the web, but came up with nothing at all (which is part of the reason why I decided to write this down, maybe it will help someone on the future). After that, I started to try and hunt down where the sub blocking was defined. At that point things started to resemble a maze of twisty passages, all alike. Following the use and require statements became a wild goose chase. For /usr/local/bin/perl, @INC contains:

/usr/local/lib/perl5/5.8.3/i386-freebsd /usr/local/lib/perl5/5.8.3 /usr/local/lib/perl5/site_perl/5.8.3/i386-freebsd /usr/local/lib/perl5/site_perl/5.8.3 /usr/local/lib/perl5/site_perl/5.8.0/i386-freebsd /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl

That's an awfully long list. I started to wonder if I didn't have a problem with inter-version mismatches. To test this out, I added the following to the top of my script:

BEGIN { @INC = (qw( /usr/local/lib/perl5/5.8.3/i386-freebsd /usr/local/lib/perl5/5.8.3 /usr/local/lib/perl5/site_perl/5.8.3/i386-freebsd /usr/local/lib/perl5/site_perl/5.8.3 /usr/local/lib/perl5/site_perl . )); }

Things fell apart immediately at this point, because perl could no longer find the other modules that the program required. So I fired up a CPAN shell, and installed things as required. And at the end of it all... no more error messages. What is more, now that the modules are installed for 5.8.3, I can remove the @INC kluge and the program works without squawking.

In an ideal world, I should see what I've installed on this machine for 5.005_03, 5.6.1 and 5.8.0 and reinstall them explicitly for 5.8.3 and delete the old directories once and for all (notwithstanding the libraries for the perl that is bundled with the OS, of course).

So that's that, may this help someone some day...


In reply to Attempt to free unreferenced scalar: (or how I learnt to stop worrying and love @INC) by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.