k2la opened a new pull request #159:
URL: https://github.com/apache/pulsar-client-node/pull/159


   ### Motivation
   I run the following code with valgrind and it looks like there are a memory 
leak in MessageId::ToString.
   
   ```
     // Receive messages
     for (let i = 0; i < 1000; i += 1) {
       const msg = await consumer.receive();
       console.log(msg.getMessageId().toString());
       console.log(msg.getData().toString());
       consumer.acknowledge(msg);
     }
   ```
   
   ```
   ...
   ==20476== 13,890 bytes in 1,000 blocks are definitely lost in loss record 68 
of 68
   ==20476==    at 0x4C29F73: malloc (vg_replace_malloc.c:309)
   ==20476==    by 0x5B03BD9: strndup (in /usr/lib64/libc-2.17.so)
   ==20476==    by 0x9EA3D74: pulsar_message_id_str (in 
/usr/lib/libpulsar.so.2.7.1)
   ==20476==    by 0x9A73E6A: MessageId::ToString(Napi::CallbackInfo const&) 
(in /home/k2la/pulsar-client-node/build/Release/Pulsar.node)
   ==20476==    by 0x9A7BFE0: 
Napi::ObjectWrap<MessageId>::InstanceMethodCallbackWrapper(napi_env__*, 
napi_callback_info__*) (in 
/home/k2la/pulsar-client-node/build/Release/Pulsar.node)
   ==20476==    by 0x9D1E04: v8impl::(anonymous 
namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> 
const&) (in /usr/bin/node)
   ==20476==    by 0xC065F8: v8::internal::MaybeHandle<v8::internal::Object> 
v8::internal::(anonymous 
namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, 
v8::internal::Handle<v8::internal::HeapObject>, 
v8::internal::Handle<v8::internal::HeapObject>, 
v8::internal::Handle<v8::internal::FunctionTemplateInfo>, 
v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (in 
/usr/bin/node)
   ==20476==    by 0xC083E6: v8::internal::Builtin_HandleApiCall(int, unsigned 
long*, v8::internal::Isolate*) (in /usr/bin/node)
   ==20476==    by 0x140DF98: ??? (in /usr/bin/node)
   ==20476==    by 0x1393723: ??? (in /usr/bin/node)
   ==20476==    by 0x13BDFD2: ??? (in /usr/bin/node)
   ==20476==    by 0x13E26D1: ??? (in /usr/bin/node)
   ...
   ```
   
   ### Modification
   Free `char*` value obtained by `pulsar_message_id_str`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to