summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2012-05-10 11:19:37 -0400
committerAlan Antonuk <alan.antonuk@gmail.com>2012-05-10 11:19:37 -0400
commit416b7b10ff85b90028ddb35cb4d3559fe85f3f5b (patch)
tree2b531f20342a0229f2b163d6b8088a97124311cf
parent54024feb76652c6a534b3792d0efa13116ec4bd5 (diff)
downloadrabbitmq-c-github-ask-416b7b10ff85b90028ddb35cb4d3559fe85f3f5b.tar.gz
Fix: double free() if amqp_tune_connection fails in amqp_new_connection
See: https://github.com/rabbitmq/rabbitmq-c/issues/6
-rw-r--r--librabbitmq/amqp_connection.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c
index 294910e..fc99862 100644
--- a/librabbitmq/amqp_connection.c
+++ b/librabbitmq/amqp_connection.c
@@ -55,6 +55,7 @@
}
amqp_connection_state_t amqp_new_connection(void) {
+ int res;
amqp_connection_state_t state =
(amqp_connection_state_t) calloc(1, sizeof(struct amqp_connection_state_t_));
@@ -64,7 +65,10 @@ amqp_connection_state_t amqp_new_connection(void) {
init_amqp_pool(&state->frame_pool, INITIAL_FRAME_POOL_PAGE_SIZE);
init_amqp_pool(&state->decoding_pool, INITIAL_DECODING_POOL_PAGE_SIZE);
- if (amqp_tune_connection(state, 0, INITIAL_FRAME_POOL_PAGE_SIZE, 0) != 0)
+ res = amqp_tune_connection(state, 0, INITIAL_FRAME_POOL_PAGE_SIZE, 0);
+ if (-ERROR_NO_MEMORY == res)
+ return NULL;
+ else if (0 != res)
goto out_nomem;
state->inbound_buffer.bytes = amqp_pool_alloc(&state->frame_pool, state->inbound_buffer.len);