in reply to Re: Re: Attempt to free unreferenced scalar...
in thread Attempt to free unreferenced scalar...

Do you still get the "attempt to free unreferenced scalar" message if you comment out the line that says $SIG{CHLD} = \&REAPER;?

If so, you have probably found a real bug in Perl and you should prepare a bug report. Try trimming the code down some more by getting rid of some of the more peripheral subroutines. Use the perlbug program on your system to report the error, including the entire source code of the smallest version of the program you can find that still demonstrates the problem.

If commenting out the $SIG{CHLD} line makes the problem magically go away, then you've still found a bug in Perl, but it's a well-known bug that people don't know how to fix. In this case you can still solve your problem by avoiding signal handlers and using waitpid to reap the children. If you post about it I will help you fix the program to do this.

Thanks for taking so much time to investigate this.

Replies are listed 'Best First'.
Re: Attempt to free unreferenced scalar...
by Daniellek (Sexton) on Dec 01, 2000 at 15:01 UTC
    I commented $SIG{CHLD} and the problem really went away!!!

    I would really appreciate if help me to walk around this...

    One thing is really important for me, it has to be still multithreaded.
    Is this possible with waitpid? I read perldoc -f waitpid and there is some example how to use it "non-blocking" way, but i'm not convinced...

    Waiting for Your reply...

    PS. I'm the person to thank You all for guiding me how to find the real problem :)

    -- Daniellek
      > I commented $SIG{CHLD} and the problem really went away!!!
      Good, that's what I thought it was all along.

      >it has to be still multithreaded. Is this possible with waitpid?

      Oh, yes, that's why I suggested it. The key to the multithreadedness of your program is the spawn function. You aren't even going to touch the spawn function.

      The example of what you need to do is in the manual. If you do waitpid(-1, &WNOHANG), then it checks to see if there is a zombie, and if there is one, it cleans it up. Unlike wait, it returns immediately whether there is a zombie or not. If you use:

      do { $kid = waitpid(-1,&WNOHANG); } until $kid == -1;

      then your program will clean up all the outstanding zombies. If there are no zombies, waitpid will return -1 immediately and the loop will execute only once.

      You can stick this code into your program at the top of the main loop, and every time your server accepts a new client, it will try to clean up any outstanding zombies. Get rid of $waitedpid and the signal handler. Leave spawn the way it is. Put the waitpid loop in just before the call to spawn. Don't forget to use POSIX ":sys_wait_h" like it says in perlfunc.

      Hope this helps. Send me email if you can't get it working.

        OK, I did it as you said and... it works!
        No more errors, no more unhappy people ;)

        Thanks! If you ever be in Krakow (Poland), I'll buy you a beer :)

        -- Daniellek