OCT 1.修正接口功能的内存泄漏

2.修正删除接口参数异常判断
This commit is contained in:
dongwenze 2023-03-03 16:37:52 +08:00
parent 26359affa0
commit 3f91f98a22
1 changed files with 23 additions and 9 deletions

View File

@ -471,7 +471,6 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
cJSON *pdel_Item = cJSON_CreateObject(); cJSON *pdel_Item = cJSON_CreateObject();
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i); cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
char del_range[256]; char del_range[256];
auto *delItem = (PHASH_MAP)malloc(sizeof(HASH_MAP));
if (!pdelRange) { if (!pdelRange) {
continue; continue;
@ -486,17 +485,21 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
mySplit(start, end, del_range, '-'); mySplit(start, end, del_range, '-');
st_addr = htonl(inet_addr(start)); st_addr = htonl(inet_addr(start));
en_addr = htonl(inet_addr(end)); en_addr = htonl(inet_addr(end));
if (en_addr == 0) {
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
if (st_addr > en_addr) {
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
cJSON_AddNumberToObject(pdel_Item, "status", ERR_INPUT_PARAMS); cJSON_AddNumberToObject(pdel_Item, "status", ERR_INPUT_PARAMS);
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS)); cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS));
cJSON_AddItemToArray(pdelArray, pdel_Item); cJSON_AddItemToArray(pdelArray, pdel_Item);
break;
} else {
cJSON_Delete(pdel_Item);
} }
HASH_FIND_INT(delMap, &st_addr, delItem); PHASH_MAP s;
if (delItem == nullptr) { HASH_FIND_INT(delMap, &st_addr, s);
auto *s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); if (s == nullptr) {
s = (PHASH_MAP)malloc(sizeof(HASH_MAP));
s->key = st_addr; s->key = st_addr;
s->value = en_addr; s->value = en_addr;
HASH_ADD_INT(delMap, key, s); HASH_ADD_INT(delMap, key, s);
@ -533,14 +536,22 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
} }
HASH_DEL(delMap, delRange); HASH_DEL(delMap, delRange);
free(delRange);
free(cfig.dhcpRanges[i].options);
free(cfig.dhcpRanges[i].expiry);
free(cfig.dhcpRanges[i].dhcpEntry);
free(*(cfig.dhcpRanges[i].dhcpEntry));
} else { } else {
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13)); memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
resCount++; resCount++;
cJSON_Delete(pdel_Item);
} }
} }
//The input parameter does not exist //The input parameter does not exist
if (resCount > cfig.rangeCount - cJSON_GetArraySize(pdhcp_range)) { do {
auto *s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); PHASH_MAP s;
PHASH_MAP tmp; PHASH_MAP tmp;
char saddr[128]; char saddr[128];
char eaddr[128]; char eaddr[128];
@ -558,8 +569,11 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS); cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS);
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS)); cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS));
cJSON_AddItemToArray(pdelArray, pdel_Item); cJSON_AddItemToArray(pdelArray, pdel_Item);
HASH_DEL(delMap, s);
free(s);
} }
} } while (0);
//Rewrite cfig.dhcpRanges //Rewrite cfig.dhcpRanges
for (int i = 0; i < cfig.rangeCount; i++) { for (int i = 0; i < cfig.rangeCount; i++) {