Skip to content

Commit

Permalink
Fix reported memory leaks when php built with --enbale-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Jan 25, 2015
1 parent c21f45c commit 222c90f
Show file tree
Hide file tree
Showing 14 changed files with 526 additions and 330 deletions.
6 changes: 4 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "trusty64"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
#config.vm.box = "trusty64"
config.vm.box = "utopic64"
#config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-amd64-vagrant-disk1.box"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
Expand Down
14 changes: 7 additions & 7 deletions amqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,15 @@ zend_function_entry amqp_connection_class_functions[] = {
PHP_ME(amqp_connection_class, getTimeout, arginfo_amqp_connection_class_getTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setTimeout, arginfo_amqp_connection_class_setTimeout, ZEND_ACC_PUBLIC)

PHP_ME(amqp_connection_class, getReadTimeout, arginfo_amqp_connection_class_getReadTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setReadTimeout, arginfo_amqp_connection_class_setReadTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getReadTimeout, arginfo_amqp_connection_class_getReadTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setReadTimeout, arginfo_amqp_connection_class_setReadTimeout, ZEND_ACC_PUBLIC)

PHP_ME(amqp_connection_class, getWriteTimeout, arginfo_amqp_connection_class_getWriteTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getWriteTimeout, arginfo_amqp_connection_class_getWriteTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC)

PHP_ME(amqp_connection_class, getUsedChannels, arginfo_amqp_connection_class_getUsedChannels, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getMaxChannels, arginfo_amqp_connection_class_getMaxChannels, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, isPersistent, arginfo_amqp_connection_class_isPersistent, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getUsedChannels, arginfo_amqp_connection_class_getUsedChannels, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getMaxChannels, arginfo_amqp_connection_class_getMaxChannels, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, isPersistent, arginfo_amqp_connection_class_isPersistent, ZEND_ACC_PUBLIC)

{NULL, NULL, NULL} /* Must be the last line in amqp_functions[] */
};
Expand Down
45 changes: 27 additions & 18 deletions amqp_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ void php_amqp_close_channel(amqp_channel_object *channel TSRMLS_DC)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -230,11 +231,12 @@ PHP_METHOD(amqp_channel_class, __construct)

PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand All @@ -259,11 +261,12 @@ PHP_METHOD(amqp_channel_class, __construct)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -351,11 +354,12 @@ PHP_METHOD(amqp_channel_class, setPrefetchCount)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -422,11 +426,12 @@ PHP_METHOD(amqp_channel_class, setPrefetchSize)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -501,11 +506,12 @@ PHP_METHOD(amqp_channel_class, qos)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -548,11 +554,12 @@ PHP_METHOD(amqp_channel_class, startTransaction)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -594,11 +601,12 @@ PHP_METHOD(amqp_channel_class, commitTransaction)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down Expand Up @@ -639,11 +647,12 @@ PHP_METHOD(amqp_channel_class, rollbackTransaction)
if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();

php_amqp_error(res, message, connection, channel TSRMLS_CC);
php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC);

php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC);
php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC);
php_amqp_maybe_release_buffers_on_channel(connection, channel);

PHP_AMQP_DESTROY_ERROR_MESSAGE();
return;
}

Expand Down
4 changes: 2 additions & 2 deletions amqp_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ HashTable *amqp_connection_object_get_debug_info(zval *object, int *is_temp TSRM

if (connection && connection->connection_resource) {
ZVAL_RESOURCE(value, connection->connection_resource->resource_id);
zend_list_addref(connection->connection_resource->resource_id);
zend_list_addref(connection->connection_resource->resource_id);
} else {
ZVAL_NULL(value);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ int php_amqp_connect(amqp_connection_object *connection, int persistent TSRMLS_D
if (persistent) {
zend_rsrc_list_entry *le;
/* Look for an established resource */
key_len = spprintf(&key, 0, "amqp_conn_res_%s_%d_%s_%s_%s", connection->host, connection->port, connection->vhost, connection->login, connection->password);
key_len = spprintf(&key, 0, "amqp_conn_res_%s_%d_%s_%s_%s", connection->host, connection->port, connection->vhost, connection->login, connection->password);

if (zend_hash_find(&EG(persistent_list), key, key_len + 1, (void **)&le) == SUCCESS) {
efree(key);
Expand Down
28 changes: 16 additions & 12 deletions amqp_connection_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connec

/* Check if there are any open slots */
if (resource->used_slots >= PHP_AMQP_MAX_CHANNELS + 1) {
return 0;
}
return 0;
}

amqp_channel_t slot;

Expand Down Expand Up @@ -274,11 +274,11 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object
struct timeval *tv_ptr = &tv;

char *std_datetime;
amqp_table_entry_t client_properties_entries[5];
amqp_table_t client_properties_table;
amqp_table_entry_t client_properties_entries[5];
amqp_table_t client_properties_table;

amqp_table_entry_t custom_properties_entries[1];
amqp_table_t custom_properties_table;
amqp_table_entry_t custom_properties_entries[1];
amqp_table_t custom_properties_table;

amqp_connection_resource *resource;

Expand Down Expand Up @@ -350,8 +350,8 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object
client_properties_entries[4].value.kind = AMQP_FIELD_KIND_UTF8;
client_properties_entries[4].value.value.bytes = amqp_cstring_bytes(std_datetime);

client_properties_table.entries = client_properties_entries;
client_properties_table.num_entries = sizeof(client_properties_entries) / sizeof(amqp_table_entry_t);
client_properties_table.entries = client_properties_entries;
client_properties_table.num_entries = sizeof(client_properties_entries) / sizeof(amqp_table_entry_t);

custom_properties_entries[0].key = amqp_cstring_bytes("client");
custom_properties_entries[0].value.kind = AMQP_FIELD_KIND_TABLE;
Expand All @@ -377,12 +377,16 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object
efree(std_datetime);

if (res.reply_type != AMQP_RESPONSE_NORMAL) {
PHP_AMQP_INIT_ERROR_MESSAGE();
char *message, *long_message;

php_amqp_connection_resource_error(res, &message, resource, 0 TSRMLS_CC);

spprintf(&long_message, 0, "%s - Potential login failure.", message);
zend_throw_exception(amqp_connection_exception_class_entry, long_message, 0 TSRMLS_CC);

php_amqp_connection_resource_error(res, message, resource, 0 TSRMLS_CC);
efree(message);
efree(long_message);

strcat(*message, " - Potential login failure.");
zend_throw_exception(amqp_connection_exception_class_entry, *message, 0 TSRMLS_CC);
/* https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf
*
* 2.2.4 The Connection Class:
Expand Down
7 changes: 2 additions & 5 deletions amqp_envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,8 @@ PHP_METHOD(amqp_envelope_class, getHeaders)
/* Get the envelope object out of the store */
envelope = (amqp_envelope_object *)zend_object_store_get_object(id TSRMLS_CC);

*return_value = *envelope->headers;
zval_copy_ctor(return_value);

/* Increment the ref count */
Z_ADDREF_P(envelope->headers);
zval_dtor(return_value);
MAKE_COPY_ZVAL(&envelope->headers, return_value);
}
/* }}} */

Expand Down
Loading

0 comments on commit 222c90f

Please sign in to comment.