Skip to content

Commit c27ae2f

Browse files
edoardocomarwebmakersteve
authored andcommitted
fix for key of zero length on Ubuntu 14 (#53)
1 parent 806d6f5 commit c27ae2f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/producer.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,19 @@ NAN_METHOD(Producer::NodeProduce) {
322322
v8::Local<v8::String> val = info[3]->ToString();
323323
// Get string pointer for this thing
324324
Nan::Utf8String keyUTF8(val);
325-
std::string keyString(*keyUTF8);
326-
327-
// This will just go out of scope and we don't send it anywhere,
328-
// since it is copied there is no need to delete it
329-
key = &keyString;
325+
key = new std::string(*keyUTF8);
330326
}
331327

332328
Producer* producer = ObjectWrap::Unwrap<Producer>(info.This());
333329

334330
Baton b = producer->Produce(message_buffer_data, message_buffer_length,
335331
topic->toRDKafkaTopic(), partition, key);
336332

333+
// we can delete the key as librdkafka will take a copy of the message
334+
if (key) {
335+
delete key;
336+
}
337+
337338
// Let the JS library throw if we need to so the error can be more rich
338339
int error_code = static_cast<int>(b.err());
339340

0 commit comments

Comments
 (0)