Skip to content

Commit

Permalink
Revert "[beken-72xx] Free list returned by wlan_sta_scan_result() (li…
Browse files Browse the repository at this point in the history
…bretiny-eu#226)"

This reverts commit 1d80b5f.
  • Loading branch information
hn committed Feb 25, 2024
1 parent cf52021 commit 98e1954
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 34 deletions.
16 changes: 3 additions & 13 deletions cores/beken-72xx/arduino/libraries/WiFi/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,20 @@ static void scanHandler(void *ctx, uint8_t param) {
return;
}

uint8_t apNum = 0;
ScanResult_adv result;
result.ApNum = 0;
result.ApList = NULL;
if (wlan_sta_scan_result(&result)) {
LT_EM(WIFI, "Failed to get scan result");
goto end;
}
LT_IM(WIFI, "Found %d APs", result.ApNum);

apNum = cls->scanAlloc(result.ApNum);
if (0 == apNum) {
cls->scanAlloc(result.ApNum);
if (!scan->ap) {
LT_WM(WIFI, "scan->ap alloc failed");
goto end;
}

if (apNum < result.ApNum) {
LT_WM(WIFI, "alloc failed, only %d APs will be copied");
}

for (uint8_t i = 0; i < apNum; i++) {
for (uint8_t i = 0; i < result.ApNum; i++) {
scan->ap[i].ssid = strdup(result.ApList[i].ssid);
scan->ap[i].auth = securityTypeToAuthMode(result.ApList[i].security);
scan->ap[i].rssi = result.ApList[i].ApPower;
Expand All @@ -54,9 +47,6 @@ static void scanHandler(void *ctx, uint8_t param) {
scan->running = false;
xSemaphoreGive(cDATA->scanSem);
}
if (result.ApList) {
free(result.ApList);
}
LT_HEAP_I();
return;
}
Expand Down
24 changes: 7 additions & 17 deletions cores/common/arduino/libraries/api/WiFi/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,13 @@ void WiFiClass::scanDelete() {
}

uint8_t WiFiClass::scanAlloc(uint8_t count) {
if ((!scan->ap) || (count > scan->count)) {
auto newMem = (WiFiScanAP *)realloc(scan->ap, count * sizeof(WiFiScanAP));
if (!newMem) {
return scan->count;
}
scan->ap = newMem;
}
if (!scan->ap) {
scan->count = 0;
return 0;
}
if (count > scan->count) {
// clear only new entries
memset(scan->ap + scan->count, 0, sizeof(WiFiScanAP) * (count - scan->count));
}
scan->count = count;
return count;
uint8_t last = scan->count;
scan->count = count;
scan->ap = (WiFiScanAP *)realloc(scan->ap, count * sizeof(WiFiScanAP));
if (!scan->ap)
return 255;
memset(scan->ap + last, 0, sizeof(WiFiScanAP));
return last;
}

String WiFiClass::SSID(uint8_t networkItem) {
Expand Down
5 changes: 1 addition & 4 deletions cores/realtek-amb/arduino/libraries/WiFi/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ static rtw_result_t scanHandler(rtw_scan_handler_result_t *result) {
if (!net->SSID.len)
return RTW_SUCCESS;

uint8_t last = scan->count + 1;
if (cls->scanAlloc(last) < last) {
return RTW_SUCCESS;
}
uint8_t last = cls->scanAlloc(scan->count + 1);

scan->ap[last].ssid = strdup((char *)net->SSID.val);
scan->ap[last].auth = securityTypeToAuthMode(net->security);
Expand Down

0 comments on commit 98e1954

Please sign in to comment.