hrsakai commented on pull request #163:
URL: 
https://github.com/apache/pulsar-client-node/pull/163#issuecomment-883036429


   > The following part doesn't need to be modified because ptr is not 
shared_ptr, right?
   
   This issue seems to occure if adding same pointer to `Napi::Buffer<T>::New`, 
whether shared_ptr or not.
   For example, following code occures the error:
   ```
   Napi::Value MessageId::Serialize(const Napi::CallbackInfo &info) {
     Napi::Env env = info.Env();
   
     int len;
     void *ptr = pulsar_message_id_serialize(GetCMessageId(), &len);
   
     // OK
     Napi::Buffer<char>::New(env, (char *)ptr, len, serializeFinalizeCallback);
   
     // Check failed: result.second.
     return Napi::Buffer<char>::New(env, (char *)ptr, len, 
serializeFinalizeCallback);
   }
   
   ```
   
   
   In fact, `pulsar_message_id_serialize` executes `memcpy` and returns the 
copy each time it is called, so same pointer is not added to 
`Napi::Buffer<T>::New` in `MessageId::Serialize` and so we don't need to modify 
`MessageId::Serialize`.
   
https://github.com/apache/pulsar/blob/6704f12104219611164aa2bb5bbdfc929613f1bf/pulsar-client-cpp/lib/c/c_MessageId.cc#L46-L53
   


-- 
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.

To unsubscribe, e-mail: dev-unsubscr...@pulsar.apache.org

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


Reply via email to