diff --git a/src/workers.h b/src/workers.h index d7d5ac8a..0f936f55 100644 --- a/src/workers.h +++ b/src/workers.h @@ -100,7 +100,14 @@ class MessageWorker : public ErrorAwareWorker { } for (unsigned int i = 0; i < message_queue.size(); i++) { - HandleMessageCallback(message_queue[i], RdKafka::ERR_NO_ERROR); + if (callback && !callback->IsEmpty()) { + HandleMessageCallback(message_queue[i], RdKafka::ERR_NO_ERROR); + } else { + // cleaning up heap allocations + if (message_queue[i] != NULL) { + delete message_queue[i]; + } + } // we are done with it. it is about to go out of scope // for the last time so let's just free it up here. can't rely @@ -108,7 +115,9 @@ class MessageWorker : public ErrorAwareWorker { } for (unsigned int i = 0; i < warning_queue.size(); i++) { - HandleMessageCallback(NULL, warning_queue[i]); + if (callback && !callback->IsEmpty()) { + HandleMessageCallback(NULL, warning_queue[i]); + } } }