diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index f3cd660..20b1087 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -467,10 +467,12 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { pdelArray = cJSON_CreateArray(); cJSON_AddItemToObject(pRspRoot, "rangeSet", pdelArray); + char start[128]; + char end[128]; + char del_range[256]; for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) { cJSON *pdel_Item = cJSON_CreateObject(); cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i); - char del_range[256]; if (!pdelRange) { continue; @@ -480,8 +482,6 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { MYDWORD st_addr; MYDWORD en_addr; - char start[128]; - char end[128]; mySplit(start, end, del_range, '-'); st_addr = htonl(inet_addr(start)); en_addr = htonl(inet_addr(end)); @@ -509,17 +509,14 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { for (int i = 0; i < cfig.rangeCount; i++) { cJSON *pdel_Item = cJSON_CreateObject(); PHASH_MAP delRange; - char del_range[256]; - char saddr[128]; - char eaddr[128]; memset(del_range, 0, 256); HASH_FIND_INT(delMap, &cfig.dhcpRanges[i].rangeStart, delRange); if (delRange != nullptr) { - IP2String(saddr, ntohl(delRange->key)); - IP2String(eaddr, ntohl(delRange->value)); + IP2String(start, ntohl(delRange->key)); + IP2String(end, ntohl(delRange->value)); - sprintf(del_range, "%s-%s", saddr, eaddr); + sprintf(del_range, "%s-%s", start, end); cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); //Determine whether the input is correct or not if (delRange->value == cfig.dhcpRanges[i].rangeEnd) { @@ -527,6 +524,10 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_SUCCESS)); cJSON_AddItemToArray(pdelArray, pdel_Item); + 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++; @@ -537,11 +538,6 @@ 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++; @@ -552,16 +548,13 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) { //The input parameter does not exist PHASH_MAP s; PHASH_MAP tmp; - char saddr[128]; - char eaddr[128]; - char del_range[256]; memset(del_range, 0, 256); HASH_ITER(hh, delMap, s, tmp) HASH_ITER(hh, delMap, s, tmp) { cJSON *pdel_Item = cJSON_CreateObject(); - IP2String(saddr, ntohl(s->key)); - IP2String(eaddr, ntohl(s->value)); + IP2String(start, ntohl(s->key)); + IP2String(end, ntohl(s->value)); - sprintf(del_range, "%s-%s", saddr, eaddr); + sprintf(del_range, "%s-%s", start, end); cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS);