php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20317 memory leak by socket_sendto()
Submitted: 2002-11-08 12:24 UTC Modified: 2002-11-21 17:13 UTC
From: apan at multidas dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.2.1 OS: Redhat Linux 7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
16 - 14 = ?
Subscribe to this entry?

 
 [2002-11-08 12:24 UTC] apan at multidas dot com
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);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-08 12:28 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-11-21 17:13 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC