You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by nk...@apache.org on 2021/09/01 07:57:55 UTC
[pulsar-client-node] branch branch-1.3 updated: Branch 1.3 (#168)
This is an automated email from the ASF dual-hosted git repository.
nkurihar pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/pulsar-client-node.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 34a2954 Branch 1.3 (#168)
34a2954 is described below
commit 34a2954250d29e2981beedef5ed6eee23ba66bd3
Author: Andrey Liapin <li...@gmail.com>
AuthorDate: Wed Sep 1 10:57:50 2021 +0300
Branch 1.3 (#168)
* Use Buffer::Copy instead of Buffer::New (#163)
(cherry picked from commit f34c23b65f655bf61e176d374997dd2b89ed0976)
* fix: fix leak at MessageId::Serialize (#160)
(cherry picked from commit 07c6b1dd8132aed4e3d50ba182c25a7e8e3cf378)
* fix leak MessageId::ToString (#159)
Co-authored-by: Yuto Furuta <yf...@yahoo-corp.jp>
(cherry picked from commit 1bd357d71461c7a451fb8fb8da5750e7eb530433)
Co-authored-by: hrsakai <hs...@yahoo-corp.jp>
Co-authored-by: Yuri Mizushima <yu...@yahoo-corp.jp>
Co-authored-by: Yuto Furuta <mz...@gmail.com>
---
src/Message.cc | 2 +-
src/MessageId.cc | 11 +++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/Message.cc b/src/Message.cc
index d93264e..468c353 100644
--- a/src/Message.cc
+++ b/src/Message.cc
@@ -100,7 +100,7 @@ Napi::Value Message::GetData(const Napi::CallbackInfo &info) {
}
void *data = const_cast<void *>(pulsar_message_get_data(this->cMessage));
size_t size = (size_t)pulsar_message_get_length(this->cMessage);
- return Napi::Buffer<char>::New(env, (char *)data, size);
+ return Napi::Buffer<char>::Copy(env, (char *)data, size);
}
Napi::Value Message::GetMessageId(const Napi::CallbackInfo &info) {
diff --git a/src/MessageId.cc b/src/MessageId.cc
index ad9a195..c21a482 100644
--- a/src/MessageId.cc
+++ b/src/MessageId.cc
@@ -17,6 +17,8 @@
* under the License.
*/
+#include <stdlib.h>
+
#include "MessageId.h"
#include <pulsar/c/message.h>
#include <pulsar/c/message_id.h>
@@ -87,13 +89,15 @@ Napi::Value MessageId::Latest(const Napi::CallbackInfo &info) {
return obj;
}
+void serializeFinalizeCallback(Napi::Env env, char *ptr) { free(ptr); }
+
Napi::Value MessageId::Serialize(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
int len;
void *ptr = pulsar_message_id_serialize(GetCMessageId(), &len);
- return Napi::Buffer<char>::New(env, (char *)ptr, len);
+ return Napi::Buffer<char>::New(env, (char *)ptr, len, serializeFinalizeCallback);
}
Napi::Value MessageId::Deserialize(const Napi::CallbackInfo &info) {
@@ -117,7 +121,10 @@ Napi::Value MessageId::Deserialize(const Napi::CallbackInfo &info) {
pulsar_message_id_t *MessageId::GetCMessageId() { return this->cMessageId; }
Napi::Value MessageId::ToString(const Napi::CallbackInfo &info) {
- return Napi::String::New(info.Env(), pulsar_message_id_str(this->cMessageId));
+ char *cStr = pulsar_message_id_str(this->cMessageId);
+ std::string s(cStr);
+ free(cStr);
+ return Napi::String::New(info.Env(), s);
}
MessageId::~MessageId() {