Skip to content

Commit

Permalink
Fix #104: memory leak in poll_batch (#107)
Browse files Browse the repository at this point in the history
poll_batch currently leaks memory while initialising the queue
returned by rd_kafka_queue_get_consumer. The fix as suggested
by @mfontanini as done here is to initialise the queue with a
Queue so it's cleaned up when going out of scope.
  • Loading branch information
shashank88 authored and mfontanini committed Jul 26, 2018
1 parent d6f8129 commit df04b27
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ MessageList Consumer::poll_batch(size_t max_batch_size) {

MessageList Consumer::poll_batch(size_t max_batch_size, milliseconds timeout) {
vector<rd_kafka_message_t*> raw_messages(max_batch_size);
rd_kafka_queue_t* queue = rd_kafka_queue_get_consumer(get_handle());
ssize_t result = rd_kafka_consume_batch_queue(queue, timeout.count(), raw_messages.data(),
// Note that this will leak the queue when using rdkafka < 0.11.5 (see get_queue comment)
Queue queue(get_queue(rd_kafka_queue_get_consumer(get_handle())));
ssize_t result = rd_kafka_consume_batch_queue(queue.get_handle() , timeout.count(), raw_messages.data(),
raw_messages.size());
if (result == -1) {
check_error(rd_kafka_last_error());
Expand Down

0 comments on commit df04b27

Please sign in to comment.