From:             [EMAIL PROTECTED]
Operating system: Redhat Linux 7.3
PHP version:      4.2.1
PHP Bug Type:     Sockets related
Bug description:  memory leak by socket_sendto()

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
allocate 46080 bytes) in /usr/local/apache/htdocs/login.php on line 88,
which is the line with socket_sendto()

Here is the code:
Basically it sends a UDP request to authmsgque service,
and expect it receive some response back.

    $address = gethostbyname ('localhost');
    $service_port = getservbyname ('authmsgque', 'udp');

    /* Create a TCP/IP socket. */
    $socket = socket_create (AF_INET, SOCK_DGRAM, 0);
    if ($socket < 0) {
//        echo "socket_create() failed: reason: " . socket_strerror
($socket) . "<br>\n";
    } else {
//        echo "socket_create() OK.<br>\n";
    }

//    echo "Attempting to connect to '$address' on port
'$service_port'...<br>\n";

    $outbuf = "abc+++cde";

    for ($i = 1; $i <= 3; $i++) {
        $result = socket_sendto ( $socket, $outbuf, strlen($outbuf), 0,
$address , $service_port );
        if ($result < 0) {
//            echo "socket_sendto() failed.\nReason: ($result) " .
socket_strerror($result) . "<br>\n";
        } else {
//            echo "socket_sendto() OK.<br>\n";
        }

        $inbuf = "NO RESPONSE";
        $remote_address = "abc";
        $remote_port = 100;

        echo "Reading response:<br>\n\n";
        $result2 = 0;

        /* Prepare the read array */
        $read = array($socket);

        if (false == ($num_changed_sockets = socket_select($read, $write =
NULL, $except = NULL, 5)))
            /* Error handling */
            ;
//            echo "socket_select() failed.\nReason: timeout <br>\n";
        else if ($num_changed_sockets > 0) {
            /* At least at one of the sockets something interesting
happened */
            $result2 = socket_recvfrom ( $socket, $inbuf, 1024, 0,
$remote_address, $remote_port );
//            echo "result2 : ".$result2."<br>\n";
//            echo "remote_address : ".$remote_address."<br>\n";
//            echo "remote_port : ".$remote_port."<br>\n";
//            echo "received buffer : ".$inbuf."<br>\n";
            if ( $result2 > 0 && strcmp($inbuf,"NO RESPONSE") != 0 )
                break;
        }
    }
    socket_close ($socket);
-- 
Edit bug report at http://bugs.php.net/?id=20317&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20317&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20317&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20317&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20317&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20317&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20317&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20317&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20317&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20317&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20317&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20317&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20317&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20317&r=isapi

Reply via email to