[rabbitmq-discuss] rabbitmq-c amqp_tx_commit leak memory
Alan Antonuk
alan.antonuk at gmail.com
Mon Jul 1 16:08:42 BST 2013
You need to call amqp_maybe_releae_buffers() after amqp_tx_commit().
The rule of thumb for rabbitmq-c is if the library returns something to
you, you should release it when you're done with it by calling that
function.
On Mon, Jul 1, 2013 at 6:08 AM, Haster <haster2004 at yandex.ru> wrote:
> Hi there!
>
> I try to use transactions in my producer. And I found that when I send many
> messages - my app eat a lot of memory.
>
> If I dismiss transaction feature - memory consumption is normal
>
> Maybe there is memory leak in amqp_tx_commit? Or maybe I have to call some
> function to clean something?
>
> my test case is below:
> const char * const host = "localhost";
> int port = 5672;
> const char * const user = "admin";
> const char * const pass = "password";
> amqp_channel_t channel_exchange = 4;
> amqp_channel_t channel_queue = 5;
> const char *exchange = "haster_ex";
>
> void main () {
> amqp_connection_state_t conn = amqp_new_connection();
> if (!conn) { cout << "Connection error\n"; return;
> }
>
> int sockfd = amqp_open_socket(host, port); //5672
> if (sockfd < 0) { cout << "Opening socket error\n"; return; }
>
> amqp_set_sockfd(conn, sockfd);
>
> amqp_rpc_reply_t reply = amqp_login(conn, "/", 0, 131072, 0,
> AMQP_SASL_METHOD_PLAIN, user, pass);
> if (reply.reply_type != AMQP_RESPONSE_NORMAL)
> {amqp_destroy_connection(conn); cout << "Login error\n"; return;}
>
> amqp_channel_open(conn, channel_exchange);
> amqp_rpc_reply_t res = amqp_get_rpc_reply(conn);
> if (res.reply_type != AMQP_RESPONSE_NORMAL) {cout << "Channel open
> error\n"; amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
> amqp_destroy_connection(conn);return;}
>
>
> * amqp_tx_select(conn, channel_exchange); // If comment this - all is
> OK*
> res = amqp_get_rpc_reply(conn);
> if (res.reply_type != AMQP_RESPONSE_NORMAL) {cout << "Select error\n";
> amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
> amqp_destroy_connection(conn);return;}
>
> amqp_bytes_t message_bytes, routingKey_bytes, exchange_bytes;
> exchange_bytes.bytes = (void*)exchange;
> exchange_bytes.len = strlen(exchange);
> message_bytes.bytes = (void*)"Privrr";
> message_bytes.len = 6;
> routingKey_bytes.bytes = (void*)"key";
> routingKey_bytes.len = 3;
> amqp_basic_properties_t props;
> props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG;
> props.delivery_mode = 2;
> props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG;
> props.content_type = amqp_cstring_bytes("text/plain");
>
> amqp_bytes_t expiration;
> expiration.bytes = (void*)"1000";
> expiration.len = 4;
> props.expiration = expiration;
> props._flags |= AMQP_BASIC_EXPIRATION_FLAG;
>
> while (1) {
> int r = amqp_basic_publish(conn, channel_exchange, exchange_bytes,
> routingKey_bytes, 1, 0, &props, message_bytes);
>
> * amqp_tx_commit(conn, channel_exchange); // if comment it - all is OK
> amqp_get_rpc_reply(conn);*
> //die_on_amqp_error(amqp_get_rpc_reply(conn), "Commit error");
> }
> char ch;
> cin >> ch;
> }
>
>
>
>
>
> --
> View this message in context:
> http://rabbitmq.1065348.n5.nabble.com/rabbitmq-c-amqp-tx-commit-leak-memory-tp27717.html
> Sent from the RabbitMQ mailing list archive at Nabble.com.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130701/9155c040/attachment.htm>
More information about the rabbitmq-discuss
mailing list