Skip to content

Commit c818ae5

Browse files
committed
Merge pull request #1 from bmilekic/master
Bugfix in example code
2 parents dc56ee0 + 90dafa4 commit c818ae5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/rdkafka_example.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <ctype.h>
3636
#include <signal.h>
37+
#include <string.h>
3738

3839
/* Typical include path would be <librdkafka/rdkafkah>, but this program
3940
* is builtin from within the librdkafka source tree and thus differs. */
@@ -133,7 +134,7 @@ int main (int argc, char **argv) {
133134
/*
134135
* Producer
135136
*/
136-
char buf[1024];
137+
char buf[2048];
137138
int sendcnt = 0;
138139

139140
/* Create Kafka handle */
@@ -145,8 +146,11 @@ int main (int argc, char **argv) {
145146
fprintf(stderr, "%% Type stuff and hit enter to send\n");
146147
while (run && (fgets(buf, sizeof(buf), stdin))) {
147148
int len = strlen(buf);
149+
char *opbuf = malloc(len + 1);
150+
strncpy(opbuf, buf, len + 1);
151+
148152
/* Send/Produce message. */
149-
rd_kafka_produce(rk, topic, partition, 0, buf, len);
153+
rd_kafka_produce(rk, topic, partition, RD_KAFKA_OP_F_FREE, opbuf, len);
150154
fprintf(stderr, "%% Sent %i bytes to topic "
151155
"%s partition %i\n", len, topic, partition);
152156
sendcnt++;

0 commit comments

Comments
 (0)