php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62412
Patch destruction-order revision 2012-06-25 19:34 UTC by lars at strojny dot net

Patch destruction-order for amqp Bug #62412

Patch version 2012-06-25 19:34 UTC

Return to Bug #62412 | Download this patch
Patch Revisions:

Developer: lars@strojny.net

diff --git a/amqp_connection.c b/amqp_connection.c
index 419aee0..efc0242 100644
--- a/amqp_connection.c
+++ b/amqp_connection.c
@@ -266,17 +266,15 @@ void remove_channel_from_connection(amqp_connection_object *connection, amqp_cha
 	if (!resource) {
 		return;
 	}
-	
+
 	/* Go through the slots looking for an opening */
 	for (slot = 1; slot < DEFAULT_CHANNELS_PER_CONNECTION; slot++) {
 		if (resource->slots[slot] == channel) {
 			/* We found the channel, disconnect it: */
 			amqp_channel_close(connection->connection_resource->connection_state, channel->channel_id, AMQP_REPLY_SUCCESS);
-			
 			/* Clean up our local storage */
 			resource->slots[slot] = 0;
 			resource->used_slots--;
-			
 			return;
 		}
 	}
@@ -297,6 +295,7 @@ static void amqp_connection_resource_dtor_persistent(zend_rsrc_list_entry *rsrc
 void amqp_connection_dtor(void *object TSRMLS_DC)
 {
 	amqp_connection_object *connection = (amqp_connection_object*)object;
+	int slot;
 
 	php_amqp_disconnect(connection);
 
@@ -319,9 +318,19 @@ void amqp_connection_dtor(void *object TSRMLS_DC)
 
 	if (connection->connection_resource && connection->connection_resource->is_persistent == 0) {
 		if (connection->connection_resource->slots) {
-			efree(connection->connection_resource->slots);
+			for (slot = 1; slot < DEFAULT_CHANNELS_PER_CONNECTION; slot++) {
+				if (!connection->connection_resource->slots[slot]) {
+					continue;
+				}
+				amqp_channel_close(connection->connection_resource->connection_state, connection->connection_resource->slots[slot]->channel_id, AMQP_REPLY_SUCCESS);
+				/* Clean up our local storage */
+				connection->connection_resource->slots[slot] = 0;
+				connection->connection_resource->used_slots--;
+			}
 		}
+		efree(connection->connection_resource->slots);
 		efree(connection->connection_resource);
+		connection->connection_resource = 0;
 	}
 	
 	zend_object_std_dtor(&connection->zo TSRMLS_CC);
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 13:01:24 2021 UTC