File tree 1 file changed +6
-5
lines changed
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -322,18 +322,19 @@ NAN_METHOD(Producer::NodeProduce) {
322
322
v8::Local<v8::String> val = info[3 ]->ToString ();
323
323
// Get string pointer for this thing
324
324
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);
330
326
}
331
327
332
328
Producer* producer = ObjectWrap::Unwrap<Producer>(info.This ());
333
329
334
330
Baton b = producer->Produce (message_buffer_data, message_buffer_length,
335
331
topic->toRDKafkaTopic (), partition, key);
336
332
333
+ // we can delete the key as librdkafka will take a copy of the message
334
+ if (key) {
335
+ delete key;
336
+ }
337
+
337
338
// Let the JS library throw if we need to so the error can be more rich
338
339
int error_code = static_cast <int >(b.err ());
339
340
You can’t perform that action at this time.
0 commit comments