|Think about Loose Coupling|
Attempt to free unreferenced scalar: (or how I learnt to stop worrying and love @INC)by grinder (Bishop)
|on Jan 23, 2004 at 14:24 UTC||Need Help??|
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:
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:
... 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
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:
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:
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...