The memory leakage problem of abnormal branches is solved.

Signed-off-by: huobaobao <huobaobao@huawei.com>
This commit is contained in:
huobaobao 2024-09-20 11:07:14 +08:00
parent 025f6e4c49
commit cd26929026
2 changed files with 56 additions and 7 deletions

View File

@ -949,13 +949,23 @@ static void BleDataReceived(ConnBleDataReceivedContext *ctx)
break;
}
if (ctx->dataLen < sizeof(ConnPktHead)) {
CONN_LOGE(CONN_BLE, "the length of data is less than the length than the length of the header,"
"connId=%{public}u, dataLength=%{public}u", ctx->connectionId, ctx->dataLen);
break;
}
ConnPktHead *head = (ConnPktHead *)ctx->data;
UnpackConnPktHead(head);
CONN_LOGI(CONN_BLE,
"ble dispatch receive data, connId=%{public}u, "
"Len=%{public}u, Flg=%{public}d, Module=%{public}d, Seq=%{public}" PRId64 "",
connection->connectionId, ctx->dataLen, head->flag, head->module, head->seq);
CONN_LOGI(CONN_BLE, "ble dispatch receive data, connId=%{public}u, Len=%{public}u, Flg=%{public}d, "
"Module=%{public}d, Seq=%{public}" PRId64 "", connection->connectionId, ctx->dataLen, head->flag,
head->module, head->seq);
uint32_t pktHeadLen = ConnGetHeadSize();
if (ctx->dataLen <= pktHeadLen) {
CONN_LOGE(CONN_BLE, "the length of data is less than the length than pktHeadLen, connId=%{public}u, "
"dataLength=%{public}u, pktHeadLen=%{public}u", ctx->connectionId, ctx->dataLen, pktHeadLen);
break;
}
if (head->module == MODULE_CONNECTION) {
ReceivedControlData(connection, ctx->data + pktHeadLen, ctx->dataLen - pktHeadLen);
} else if (head->module == MODULE_OLD_NEARBY) {
@ -1541,12 +1551,14 @@ static void ConnectRequestFunc(SoftBusMessage *msg)
if (g_bleManager.state->connectRequest == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
ConnBleConnectRequestContext *ctx = (ConnBleConnectRequestContext *)msg->obj;
g_bleManager.state->connectRequest(ctx);
}
static void ClientConnectedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (g_bleManager.state->clientConnected != NULL) {
g_bleManager.state->clientConnected((uint32_t)msg->arg1);
return;
@ -1566,12 +1578,14 @@ static void ClientConnectFailedFunc(SoftBusMessage *msg)
if (g_bleManager.state->clientConnectFailed == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
BleStatusContext *ctx = (BleStatusContext *)(msg->obj);
g_bleManager.state->clientConnectFailed(ctx->connectionId, ctx->status);
}
static void ServerAcceptedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (g_bleManager.state->serverAccepted != NULL) {
g_bleManager.state->serverAccepted((uint32_t)msg->arg1);
return;
@ -1580,10 +1594,13 @@ static void ServerAcceptedFunc(SoftBusMessage *msg)
static void DataReceivedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
ConnBleDataReceivedContext *ctx = (ConnBleDataReceivedContext *)msg->obj;
if (g_bleManager.state->dataReceived == NULL) {
SoftBusFree(ctx->data);
return;
}
ConnBleDataReceivedContext *ctx = (ConnBleDataReceivedContext *)msg->obj;
g_bleManager.state->dataReceived(ctx);
}
@ -1592,12 +1609,14 @@ static void ConnectionClosedFunc(SoftBusMessage *msg)
if (g_bleManager.state->connectionClosed == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
BleStatusContext *ctx = (BleStatusContext *)(msg->obj);
g_bleManager.state->connectionClosed(ctx->connectionId, ctx->status);
}
static void ConnectionResumeFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (g_bleManager.state->connectionResume != NULL) {
g_bleManager.state->connectionResume((uint32_t)msg->arg1);
return;
@ -1606,6 +1625,7 @@ static void ConnectionResumeFunc(SoftBusMessage *msg)
static void DisconnectRequestFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (g_bleManager.state->disconnectRequest != NULL) {
g_bleManager.state->disconnectRequest((uint32_t)msg->arg1);
return;
@ -1614,6 +1634,7 @@ static void DisconnectRequestFunc(SoftBusMessage *msg)
static void PreventTimeoutFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
if (g_bleManager.state->preventTimeout != NULL) {
char *udid = (char *)msg->obj;
g_bleManager.state->preventTimeout(udid);
@ -1626,12 +1647,14 @@ static void ResetFunc(SoftBusMessage *msg)
if (g_bleManager.state->reset == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BLE, "msg is null or obj is null");
BleStatusContext *ctx = (BleStatusContext *)(msg->obj);
g_bleManager.state->reset(ctx->status);
}
static void KeepAliveTimeoutFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BLE, "msg is null");
if (g_bleManager.state->keepAliveTimeout != NULL) {
g_bleManager.state->keepAliveTimeout((uint32_t)msg->arg1, (uint32_t)msg->arg2);
return;

View File

@ -810,6 +810,12 @@ static void ClientConnectTimeoutOnConnectingState(uint32_t connectionId, const c
static void DataReceived(ConnBrDataReceivedContext *ctx)
{
if (ctx->dataLen < sizeof(ConnPktHead)) {
CONN_LOGE(CONN_BR, "the length of data is less than the length than the length of the header,"
"connId=%{public}u, dataLength=%{public}u", ctx->connectionId, ctx->dataLen);
SoftBusFree(ctx->data);
return;
}
ConnPktHead *head = (ConnPktHead *)ctx->data;
ConnBrConnection *connection = ConnBrGetConnectionById(ctx->connectionId);
if (connection == NULL) {
@ -822,8 +828,15 @@ static void DataReceived(ConnBrDataReceivedContext *ctx)
}
CONN_LOGD(CONN_BR, "connId=%{public}u, Len=%{public}u, Flg=%{public}d, Module=%{public}d, Seq=%{public}" PRId64 "",
ctx->connectionId, ctx->dataLen, head->flag, head->module, head->seq);
uint32_t pktHeadLen = ConnGetHeadSize();
if (ctx->dataLen <= pktHeadLen) {
CONN_LOGE(CONN_BR, "the length of data is less than the length than pktHeadLen, connId=%{public}u, "
"dataLength=%{public}u, pktHeadLen=%{public}u", ctx->connectionId, ctx->dataLen, pktHeadLen);
SoftBusFree(ctx->data);
return;
}
if (head->module == MODULE_CONNECTION) {
ReceivedControlData(connection, ctx->data + ConnGetHeadSize(), ctx->dataLen - ConnGetHeadSize());
ReceivedControlData(connection, ctx->data + pktHeadLen, ctx->dataLen - pktHeadLen);
} else if (head->module == MODULE_NIP_BR_CHANNEL && head->seq == (int64_t)BR_NIP_SEQ) {
NipRecvDataFromBr(ctx->connectionId, (char *)ctx->data, (int32_t)(ctx->dataLen));
} else {
@ -1089,12 +1102,14 @@ static void ConnectRequestFunc(SoftBusMessage *msg)
if (g_brManager.state->connectRequest == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
ConnBrConnectRequestContext *ctx = (ConnBrConnectRequestContext *)msg->obj;
g_brManager.state->connectRequest(ctx);
}
static void ClientConnectedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BR, "msg is null");
if (g_brManager.state->clientConnected != NULL) {
g_brManager.state->clientConnected((uint32_t)msg->arg1);
return;
@ -1103,6 +1118,7 @@ static void ClientConnectedFunc(SoftBusMessage *msg)
static void ClientConnectTimeoutFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
if (g_brManager.state->clientConnectTimeout != NULL) {
g_brManager.state->clientConnectTimeout((uint32_t)msg->arg1, (char *)msg->obj);
return;
@ -1114,12 +1130,14 @@ static void ClientConnectFailedFunc(SoftBusMessage *msg)
if (g_brManager.state->clientConnectFailed == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
ErrorContext *ctx = (ErrorContext *)(msg->obj);
g_brManager.state->clientConnectFailed(ctx->connectionId, ctx->error);
}
static void ServerAcceptedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BR, "msg is null");
if (g_brManager.state->serverAccepted != NULL) {
g_brManager.state->serverAccepted((uint32_t)msg->arg1);
return;
@ -1128,10 +1146,13 @@ static void ServerAcceptedFunc(SoftBusMessage *msg)
static void DataReceivedFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
ConnBrDataReceivedContext *ctx = (ConnBrDataReceivedContext *)msg->obj;
if (g_brManager.state->dataReceived == NULL) {
SoftBusFree(ctx->data);
return;
}
ConnBrDataReceivedContext *ctx = (ConnBrDataReceivedContext *)msg->obj;
g_brManager.state->dataReceived(ctx);
}
@ -1140,12 +1161,14 @@ static void ConnectionExceptionFunc(SoftBusMessage *msg)
if (g_brManager.state->connectionException == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
ErrorContext *ctx = (ErrorContext *)(msg->obj);
g_brManager.state->connectionException(ctx->connectionId, ctx->error);
}
static void ConnectionResumeFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BR, "msg is null");
if (g_brManager.state->connectionResume != NULL) {
g_brManager.state->connectionResume((uint32_t)msg->arg1);
return;
@ -1154,6 +1177,7 @@ static void ConnectionResumeFunc(SoftBusMessage *msg)
static void DisconnectRequestFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL, CONN_BR, "msg is null");
if (g_brManager.state->disconnectRequest != NULL) {
g_brManager.state->disconnectRequest((uint32_t)msg->arg1);
return;
@ -1162,6 +1186,7 @@ static void DisconnectRequestFunc(SoftBusMessage *msg)
static void UnpendFunc(SoftBusMessage *msg)
{
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
if (g_brManager.state->unpend != NULL) {
g_brManager.state->unpend((const char *)msg->obj);
return;
@ -1173,6 +1198,7 @@ static void ResetFunc(SoftBusMessage *msg)
if (g_brManager.state->reset == NULL) {
return;
}
CONN_CHECK_AND_RETURN_LOGW(msg != NULL && msg->obj != NULL, CONN_BR, "msg is null or obj is null");
ErrorContext *ctx = (ErrorContext *)(msg->obj);
g_brManager.state->reset(ctx->error);
}