From 68d23225a38a35f1325eb39fa4ed5a005d5de473 Mon Sep 17 00:00:00 2001 From: fujuntang <fujuntang@aiot.com> Date: 星期三, 11 八月 2021 09:50:20 +0800 Subject: [PATCH] fix from 3.1 first commit --- src/socket/shm_mod_socket.cpp | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/socket/shm_mod_socket.cpp b/src/socket/shm_mod_socket.cpp index 466d0b5..abd9477 100644 --- a/src/socket/shm_mod_socket.cpp +++ b/src/socket/shm_mod_socket.cpp @@ -10,7 +10,6 @@ } ShmModSocket::~ShmModSocket() { - // logger->debug("Close ShmModSocket...\n"); struct timespec timeout = {1, 0}; if(bus_set != NULL) { for(auto bus_iter = bus_set->begin(); bus_iter != bus_set->end(); bus_iter++) { @@ -216,6 +215,7 @@ int buf_size; char *buf; int max_buf_size; + void *buf_ptr; if((buf = (char *) malloc(MAXBUF)) == NULL) { LoggerFactory::getLogger()->error(errno, "ShmModSocket::get_bus_sendbuf malloc"); exit(1); @@ -234,13 +234,15 @@ } } - memcpy(buf, ShmModSocket::encode_bus_head(request_head), BUS_HEAD_SIZE); + buf_ptr = ShmModSocket::encode_bus_head(request_head); + memcpy(buf, buf_ptr, BUS_HEAD_SIZE); if(topic_size != 0 ) memcpy(buf + BUS_HEAD_SIZE, topic_buf, topic_size); if(content_size != 0) memcpy(buf + BUS_HEAD_SIZE + topic_size, content_buf, content_size); *retbuf = buf; + free(buf_ptr); return buf_size; } @@ -259,7 +261,7 @@ tmp_ptr += sizeof(head.action); PUT(tmp_ptr, htonl(head.topic_size)); - tmp_ptr += 4; + tmp_ptr += sizeof(head.topic_size); PUT(tmp_ptr, htonl(head.content_size)); return headbs; @@ -274,7 +276,7 @@ tmp_ptr += sizeof(head.action); head.topic_size = ntohl(GET(tmp_ptr)); - tmp_ptr += 4; + tmp_ptr += sizeof(head.topic_size); head.content_size = ntohl(GET(tmp_ptr)); return head; -- Gitblit v1.8.0