!7937 Abnormal branch did not use SoftBusMutexDestroy to free memory

Merge pull request !7937 from Zhangzi/master
This commit is contained in:
openharmony_ci 2024-10-13 02:48:30 +00:00 committed by Gitee
commit 9206b938ce
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 24 additions and 5 deletions

View File

@ -1156,7 +1156,11 @@ int32_t TransUdpChannelInit(IServerChannelCallBack *callback)
TRANS_INIT, "g_udpNegLock init failed.");
ret = TransUdpChannelMgrInit();
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_INIT, "trans udp channel manager init failed.");
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "trans udp channel manager init failed.");
(void)SoftBusMutexDestroy(&g_udpNegLock);
return ret;
}
AuthTransListener transUdpCb = {
.onDataReceived = UdpModuleCb,
@ -1165,7 +1169,11 @@ int32_t TransUdpChannelInit(IServerChannelCallBack *callback)
};
ret = RegAuthTransListener(MODULE_UDP_INFO, &transUdpCb);
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_INIT, "register udp callback to auth failed.");
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "register udp callback to auth failed.");
(void)SoftBusMutexDestroy(&g_udpNegLock);
return ret;
}
TRANS_LOGI(TRANS_INIT, "server trans udp channel init success.");
return SOFTBUS_OK;

View File

@ -26,6 +26,7 @@ int32_t TransTdcCreateListener(int32_t fd);
void TransTdcReleaseFd(int32_t fd);
int32_t TransTdcStopRead(int32_t fd);
void TransTdcCloseFd(int32_t fd);
void TdcLockDeinit(void);
#ifdef __cplusplus
}

View File

@ -49,6 +49,13 @@ static void TdcLockInit(void)
atomic_store_explicit(&(g_lock.lockInit), true, memory_order_release);
}
}
void TdcLockDeinit(void)
{
g_lock.lockInit = false;
(void)SoftBusMutexDestroy(&g_lock.lock);
}
static int32_t ClientTdcOnConnectEvent(ListenerModule module, int cfd,
const ConnectOption *clientAddr)
{

View File

@ -155,7 +155,7 @@ void TransTdcCloseChannel(int32_t channelId)
TransTdcReleaseFd(item->detail.fd);
item->detail.needRelease = true;
if (item->detail.fdRefCnt <= 0) {
SoftBusMutexDestroy(&(item->detail.fdLock));
(void)SoftBusMutexDestroy(&(item->detail.fdLock));
ListDelete(&item->node);
SoftBusFree(item);
item = NULL;
@ -190,11 +190,13 @@ static TcpDirectChannelInfo *TransGetNewTcpChannel(const ChannelInfo *channel)
return NULL;
}
if (memcpy_s(item->detail.sessionKey, SESSION_KEY_LENGTH, channel->sessionKey, SESSION_KEY_LENGTH) != EOK) {
(void)SoftBusMutexDestroy(&(item->detail.fdLock));
SoftBusFree(item);
TRANS_LOGE(TRANS_SDK, "sessionKey copy failed");
return NULL;
}
if (strcpy_s(item->detail.myIp, IP_LEN, channel->myIp) != EOK) {
(void)SoftBusMutexDestroy(&(item->detail.fdLock));
SoftBusFree(item);
TRANS_LOGE(TRANS_SDK, "myIp copy failed");
return NULL;
@ -244,7 +246,7 @@ static void TransTdcDelChannelInfo(int32_t channelId, int32_t errCode)
TransTdcReleaseFd(item->detail.fd);
}
ListDelete(&item->node);
SoftBusMutexDestroy(&(item->detail.fdLock));
(void)SoftBusMutexDestroy(&(item->detail.fdLock));
SoftBusFree(item);
item = NULL;
(void)SoftBusMutexUnlock(&g_tcpDirectChannelInfoList->lock);
@ -392,6 +394,7 @@ void TransTdcManagerDeinit(void)
DestroySoftBusList(g_tcpDirectChannelInfoList);
g_tcpDirectChannelInfoList = NULL;
PendingDeinit(PENDING_TYPE_DIRECT);
TdcLockDeinit();
}
int32_t ClientTransTdcOnChannelOpenFailed(int32_t channelId, int32_t errCode)
@ -468,7 +471,7 @@ void TransUpdateFdState(int32_t channelId)
if (item->channelId == channelId) {
item->detail.fdRefCnt--;
if (item->detail.needRelease && item->detail.fdRefCnt <= 0) {
SoftBusMutexDestroy(&(item->detail.fdLock));
(void)SoftBusMutexDestroy(&(item->detail.fdLock));
ListDelete(&item->node);
SoftBusFree(item);
item = NULL;