php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61603 Memory Leak in Queue Get
Submitted: 2012-04-02 21:31 UTC Modified: 2012-05-23 21:15 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:0 (0.0%)
From: hyallred at gmail dot com Assigned: pdezwart (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.10 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hyallred at gmail dot com
New email:
PHP Version: OS:

 

 [2012-04-02 21:31 UTC] hyallred at gmail dot com
Description:
------------
There is a memory leak when using the get method on a queue in a while loop when 
there are no messages in the queue. I was using version 1.0.1 of the amqp 
extension. There is a simple fix for this that I found. Before line 207 in 
amqp_queue.c where it returns AMQP_READ_NO_MESSAGES, release the memory allocated 
for the envelopeZval with:

"zval_dtor(envelopeZval);"

This should fix the leak when no messages are in queue and prevent the script's 
memory footprint from growing.

Test script:
---------------
#!/usr/bin/php -q
<?php
// This assumes you have an exchange named 'exchange.hello' set up.
$connection = new AMQPConnection(); $connection->connect();
$channel = new AMQPChannel($connection);
$q = new AMQPQueue($channel); $q->setName('queue.hello'); $q->declare();
$start = time();
while (true)
{
	$msg = $q->get(AMQP_AUTOACK);
	if (time() - $start > 2) // print out memory usage every 2 secs.
	{
		$start = time();
		echo memory_get_usage() . "\n";
	}
}
$connection->disconnect(); // disconnect

Expected result:
----------------
I expect the memory usage amount to remain constant when no messages are in the 
queue to process.

Actual result:
--------------
The memory usage value grows and grows until I run out of memory.

Patches

amqp_queue.c.patch (last revision 2012-04-18 13:31 UTC by zircote at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-09 11:44 UTC] hyallred at gmail dot com
Im getting the same result with the same version of AMQP.

[test@amqp ~]$ php test.php 
14800104
34474568
53960096
74609296
93844928
115177728
134429800
 [2012-05-21 19:27 UTC] 66ton99 at gmail dot com
I is fixed in v1.0.3
 [2012-05-23 21:15 UTC] pdezwart@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pdezwart
 [2012-05-23 21:15 UTC] pdezwart@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 30 15:01:23 2021 UTC