php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63350 Memory leak
Submitted: 2012-10-24 21:44 UTC Modified: 2013-04-17 15:24 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:0 of 1 (0.0%)
From: imprec at gmail dot com Assigned: bkw (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.4.8 OS: Mac OSX
Private report: No CVE-ID: None
 [2012-10-24 21:44 UTC] imprec at gmail dot com
Description:
------------
When running code whith php compiled with "--enable-debug", memory leak is 
reported :
[Wed Oct 24 23:42:24 2012]  Script:  '/private/tmp/RabbitMQ/test.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(407) :  Freeing 0x1030259F0 (6 
bytes), 
script=/private/tmp/RabbitMQ/test.php
Last leak repeated 1 time
[Wed Oct 24 23:42:24 2012]  Script:  '/private/tmp/RabbitMQ/test.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(425) :  Freeing 0x103026828 (6 
bytes), 
script=/private/tmp/RabbitMQ/test.php
Last leak repeated 1 time
[Wed Oct 24 23:42:24 2012]  Script:  '/private/tmp/RabbitMQ/test.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(459) :  Freeing 0x103026A78 (2 
bytes), 
script=/private/tmp/RabbitMQ/test.php
Last leak repeated 1 time
=== Total 6 memory leaks detected ===

Test script:
---------------
The script is this one : 



function amqp_connection() {
    $amqpConnection = new AMQPConnection();
    $amqpConnection->setLogin("guest");
    $amqpConnection->setPassword("guest");
    $amqpConnection->setVhost("/");
    $amqpConnection->connect();

    if(!$amqpConnection->isConnected()) {
        die("Cannot connect to the broker, exiting !\n");
    }
    return $amqpConnection;
}

function amqp_receive($exchangeName, $routingKey, $queueName) {
    $amqpConnection = amqp_connection();

    $channel = new AMQPChannel($amqpConnection);
    $queue = new AMQPQueue($channel);
    $queue->setName($queueName);
    $queue->bind($exchangeName, $routingKey);

    while($message = $queue->get()) {
        echo("Message #".$message->getDeliveryTag()." '".$message->getBody()."'");

        if($message->isRedelivery()) {
            echo("\t(this message has already been delivered)");
        }
        // just for testing purpose, shows how to manually remove a message from queue
        if(rand(0,6) > 4) {
            $queue->ack($message->getDeliveryTag());
            echo("\t(this message has been removed from the queue)");
        }
        print_r($message->getMessageId());
        echo "\n";
    }

    if(!$amqpConnection->disconnect()) {
        throw new Exception("Could not disconnect !");
    }
}

function amqp_send($text, $routingKey, $exchangeName){
    $amqpConnection = amqp_connection();

    $channel = new AMQPChannel($amqpConnection);
    $exchange = new AMQPExchange($channel);
    $exchange->setName($exchangeName);
    $exchange->setType("fanout");
        $message = $exchange->publish($text, $routingKey);
        if(!$message) {
        echo "Error: Message '".$message."' was not sent.\n";
    } else {
        echo "Message '".$message."' sent.\n";
    }

    if (!$amqpConnection->disconnect()) {
        throw new Exception("Could not disconnect !");
    }
}

// lets send a message with a "random" content (the date)
amqp_send("Message added at this date: ".date(DATE_RFC822), "action", "amq.fanout");

// you need to sleep for 1 sec if you want to be able to receive the message you just sent ("limitation" must be on the broker side)
sleep(1);

// now we receive messages from the queue we just sent a message on
amqp_receive("amq.fanout","action","action");

Expected result:
----------------
There should not be any memory leak

Actual result:
--------------
A memory leak appears

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-14 00:39 UTC] bkw at codingforce dot com
thanks for reporting this. Could you supply the output of this command on the 
host that gave the leak warnings?

  php --ri amqp
 [2012-12-18 09:30 UTC] imprec at gmail dot com
Sorry for the late reply, here is the output :

amqp

Version => 1.0.7
Revision => $Revision: 327551 $
Compiled => Dec 18 2012 @ 10:21:09
AMQP protocol version => 0-9-1

Directive => Local Value => Master Value
amqp.host => localhost => localhost
amqp.vhost => / => /
amqp.port => 5672 => 5672
amqp.login => guest => guest
amqp.password => guest => guest
amqp.auto_ack => 0 => 0
amqp.prefetch_count => 3 => 3



Do not worry, I recompiled it this morning, but the output is still the same : 

Message '1' sent.
[Tue Dec 18 10:29:33 2012]  Script:  '/usr/local/src/amqp-1.0.7/bim.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(425) :  Freeing 0x102104818 (6 
bytes), script=/usr/local/src/amqp-1.0.7/bim.php
Last leak repeated 1 time
[Tue Dec 18 10:29:33 2012]  Script:  '/usr/local/src/amqp-1.0.7/bim.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(459) :  Freeing 0x102104A68 (2 
bytes), script=/usr/local/src/amqp-1.0.7/bim.php
Last leak repeated 1 time
[Tue Dec 18 10:29:33 2012]  Script:  '/usr/local/src/amqp-1.0.7/bim.php'
/usr/local/src/amqp-1.0.7/amqp_connection.c(407) :  Freeing 0x102104E78 (6 
bytes), script=/usr/local/src/amqp-1.0.7/bim.php
Last leak repeated 1 time
=== Total 6 memory leaks detected ===
 [2012-12-29 11:47 UTC] imprec at gmail dot com
I confirm that the memory leak issue is still present in version 1.0.9 running 
on PHP 5.4.10, see the output of the script :


Message '1' sent.
[Sat Dec 29 12:45:03 2012]  Script:  '/usr/local/src/amqp-1.0.9/test.php'
/usr/local/src/amqp-1.0.9/amqp_connection.c(465) :  Freeing 0x1131A70D8 (6 
bytes), script=/usr/local/src/amqp-1.0.9/test.php
Last leak repeated 1 time
[Sat Dec 29 12:45:03 2012]  Script:  '/usr/local/src/amqp-1.0.9/test.php'
/usr/local/src/amqp-1.0.9/amqp_connection.c(483) :  Freeing 0x1131A7E28 (6 
bytes), script=/usr/local/src/amqp-1.0.9/test.php
Last leak repeated 1 time
[Sat Dec 29 12:45:03 2012]  Script:  '/usr/local/src/amqp-1.0.9/test.php'
/usr/local/src/amqp-1.0.9/amqp_connection.c(517) :  Freeing 0x110D97280 (2 
bytes), script=/usr/local/src/amqp-1.0.9/test.php
Last leak repeated 1 time
=== Total 6 memory leaks detected ===




result of php --ri amqp :

amqp

Version => 1.0.9
Revision => $Revision: 327551 $
Compiled => Dec 29 2012 @ 12:43:57
AMQP protocol version => 0-9-1
librabbitmq version => 0.0.1

Directive => Local Value => Master Value
amqp.host => localhost => localhost
amqp.vhost => / => /
amqp.port => 5672 => 5672
amqp.timeout => 0 => 0
amqp.login => guest => guest
amqp.password => guest => guest
amqp.auto_ack => 0 => 0
amqp.prefetch_count => 3 => 3


result of php - v :

PHP 5.4.10 (cli) (built: Dec 26 2012 12:18:20) (DEBUG)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans


To reproduce, please be sure to compile PHP with the --enable-debug flag
 [2013-01-14 18:49 UTC] pinepain at gmail dot com
Thanks for reporting. Can you provide sw_ver output? (/usr/bin/sw_ver).

And if you don't mind, can you open issue on official github repo (https://github.com/pdezwart/php-amqp/issues)
 [2013-04-17 15:24 UTC] bkw@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bkw
 [2013-04-17 15:24 UTC] bkw@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

this has been fixed in the github repo and will be in the next release.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 29 01:03:36 2021 UTC