From 3f91f98a22e577d71ad3dbf4fe6aa875d606ed72 Mon Sep 17 00:00:00 2001 From: dongwenze Date: Fri, 3 Mar 2023 16:37:52 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=E4=BF=AE=E6=AD=A3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= =?UTF-8?q?=202.=E4=BF=AE=E6=AD=A3=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=BC=82=E5=B8=B8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/opendhcp183/query.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index e71cd45..69467c9 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -471,7 +471,6 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { cJSON *pdel_Item = cJSON_CreateObject(); cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i); char del_range[256]; - auto *delItem = (PHASH_MAP)malloc(sizeof(HASH_MAP)); if (!pdelRange) { continue; @@ -486,17 +485,21 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { mySplit(start, end, del_range, '-'); st_addr = htonl(inet_addr(start)); 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_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS)); cJSON_AddItemToArray(pdelArray, pdel_Item); + break; + } else { + cJSON_Delete(pdel_Item); } - HASH_FIND_INT(delMap, &st_addr, delItem); - if (delItem == nullptr) { - auto *s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); + PHASH_MAP s; + HASH_FIND_INT(delMap, &st_addr, s); + if (s == nullptr) { + s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); s->key = st_addr; s->value = en_addr; 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); + free(delRange); + + free(cfig.dhcpRanges[i].options); + free(cfig.dhcpRanges[i].expiry); + free(cfig.dhcpRanges[i].dhcpEntry); + free(*(cfig.dhcpRanges[i].dhcpEntry)); } else { memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13)); resCount++; + + cJSON_Delete(pdel_Item); } } //The input parameter does not exist - if (resCount > cfig.rangeCount - cJSON_GetArraySize(pdhcp_range)) { - auto *s = (PHASH_MAP)malloc(sizeof(HASH_MAP)); + do { + PHASH_MAP s; PHASH_MAP tmp; char saddr[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_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS)); cJSON_AddItemToArray(pdelArray, pdel_Item); + + HASH_DEL(delMap, s); + free(s); } - } + } while (0); //Rewrite cfig.dhcpRanges for (int i = 0; i < cfig.rangeCount; i++) {