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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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)

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 10:01:27 2025 UTC