Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free payload memory in rd_kafka_example when queue is full #11

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/rdkafka_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ int main (int argc, char **argv) {
strncpy(opbuf, buf, len + 1);

/* Send/Produce message. */
rd_kafka_produce(rk, topic, partition, RD_KAFKA_OP_F_FREE, opbuf, len);
if( rd_kafka_produce(rk, topic, partition,
RD_KAFKA_OP_F_FREE, opbuf, len) == -1){
free(opbuf);
continue;
}
fprintf(stderr, "%% Sent %i bytes to topic "
"%s partition %i\n", len, topic, partition);
sendcnt++;
Expand Down
6 changes: 5 additions & 1 deletion examples/rdkafka_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ int main (int argc, char **argv) {
strncpy(opbuf, buf, len + 1);

/* Send/Produce message. */
kafka.produce(topic, partition, RD_KAFKA_OP_F_FREE, opbuf, len);
if (kafka.produce(topic, partition,
RD_KAFKA_OP_F_FREE, opbuf, len) == -1){
free(opbuf);
continue;
}
fprintf(stderr, "%% Sent %i bytes to topic "
"%s partition %i\n", len, topic, partition);
sendcnt++;
Expand Down
6 changes: 3 additions & 3 deletions rdkafkacpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Kafka{
const char * getTopic()const{return topic;}
*/

void produce(char *topic, uint32_t partition,int msgflags, char *payload, size_t len);
int produce(char *topic, uint32_t partition,int msgflags, char *payload, size_t len);

private:
rd_kafka_t *rk;
Expand All @@ -56,8 +56,8 @@ bool Kafka::setHandle(rd_kafka_type_t type,const char * broker,const rd_kafka_co
return (rk = rd_kafka_new(type, broker, conf))!=NULL;
}

void Kafka::produce(char *topic, uint32_t partition,int msgflags, char *payload, size_t len){
rd_kafka_produce(rk, topic, partition, msgflags, payload, len);
int Kafka::produce(char *topic, uint32_t partition,int msgflags, char *payload, size_t len){
return rd_kafka_produce(rk, topic, partition, msgflags, payload, len);
}

}
Expand Down