From 1e31b19633d973a01ca014baeb94cd6d2d7f768f Mon Sep 17 00:00:00 2001 From: maliang Date: Wed, 30 Oct 2024 19:35:12 +0800 Subject: [PATCH] feat:bugfix for crash Signed-off-by: maliang --- src/common/session.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/session.cpp b/src/common/session.cpp index 2665fff6..a5dc3185 100755 --- a/src/common/session.cpp +++ b/src/common/session.cpp @@ -832,7 +832,7 @@ int HdcSessionBase::Send(const uint32_t sessionId, const uint32_t channelId, con const uint8_t *data, const int dataSize) { StartTraceScope("HdcSessionBase::Send"); - HSession hSession = AdminSession(OP_QUERY, sessionId, nullptr); + HSession hSession = AdminSession(OP_QUERY_REF, sessionId, nullptr); if (!hSession) { WRITE_LOG(LOG_WARN, "Send to offline device, drop it, sessionId:%u", sessionId); return ERR_SESSION_NOFOUND; @@ -856,6 +856,7 @@ int HdcSessionBase::Send(const uint32_t sessionId, const uint32_t channelId, con uint8_t *finayBuf = new(std::nothrow) uint8_t[finalBufSize](); if (finayBuf == nullptr) { WRITE_LOG(LOG_WARN, "send allocmem err"); + --hSession->ref; return ERR_BUF_ALLOC; } bool bufRet = false; @@ -878,13 +879,17 @@ int HdcSessionBase::Send(const uint32_t sessionId, const uint32_t channelId, con if (!bufRet) { delete[] finayBuf; WRITE_LOG(LOG_WARN, "send copywholedata err for dataSize:%d", dataSize); + --hSession->ref; return ERR_BUF_COPY; } + int ret = -1; if (CMD_KERNEL_ECHO == commandFlag) { - return SendByProtocol(hSession, finayBuf, finalBufSize, true); + ret = SendByProtocol(hSession, finayBuf, finalBufSize, true); } else { - return SendByProtocol(hSession, finayBuf, finalBufSize); + ret = SendByProtocol(hSession, finayBuf, finalBufSize); } + --hSession->ref; + return ret; } int HdcSessionBase::DecryptPayload(HSession hSession, PayloadHead *payloadHeadBe, uint8_t *encBuf)