From b8b5059222cc99637d4a1c30e7eab26ca9fd0308 Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期二, 07 九月 2021 13:45:12 +0800
Subject: [PATCH] Add the dynamic buf.
---
src/bh_api.cpp | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/bh_api.cpp b/src/bh_api.cpp
index d773369..eef4870 100644
--- a/src/bh_api.cpp
+++ b/src/bh_api.cpp
@@ -1042,6 +1042,7 @@
int key;
int size;
int sec, nsec;
+ char buf_temp[100] = { 0x00 };
char *topics_buf = NULL;
char *data_buf = NULL;
@@ -1135,13 +1136,16 @@
#if defined(PRO_DE_SERIALIZE)
rsr.topic = topics_buf;
- rsr.data = data_buf;
+ if (data_buf != NULL) {
+ rsr.data = data_buf;
+ } else {
+ rsr.data = topics_buf;
+ }
- memset(topics_buf, 0x00, sizeof(topics_buf));
- sprintf(topics_buf, "%d", key);
+ sprintf(buf_temp, "%d", key);
if ((proc_id != NULL) && (proc_id_len != NULL)) {
- rsr.proc_id = topics_buf;
+ rsr.proc_id = buf_temp;
*proc_id_len = rsr.proc_id.size();
*proc_id = malloc(*proc_id_len);
memcpy(*proc_id, rsr.proc_id.data(), *proc_id_len);
@@ -1168,14 +1172,17 @@
}
*msgpub = ptr;
*msgpub_len = len;
-
+
+ free(topics_buf);
+ free(data_buf);
+
if ((proc_id != NULL) && (proc_id_len != NULL)) {
- memset(topics_buf, 0x00, sizeof(topics_buf));
- sprintf(topics_buf, "%d", key);
+ memset(buf_temp, 0x00, sizeof(buf_temp));
+ sprintf(buf_temp, "%d", key);
- *proc_id_len = strlen(topics_buf);
+ *proc_id_len = strlen(buf_temp);
*proc_id = malloc(*proc_id_len);
- memcpy(*proc_id, topics_buf, *proc_id_len);
+ memcpy(*proc_id, buf_temp, *proc_id_len);
}
#endif
--
Gitblit v1.8.0