[beken-72xx] Free list returned by wlan_sta_scan_result() (#226)
* Free list returned by wlan_sta_scan_result() * scanAlloc improvements There were a few things I didn't like about this function: 1) realloc() was called a bit too often. 2) if realloc() failed, the previous memory was not freed. 3) scanAlloc returned previous count or 255 on error. But there was no real check for error and 255 could've been used as index to null. I think it's better to simple return boolean. 4) scanAlloc was clearing memory only up to (and excluding) the new entries. * Corrected clearing new entries in scanAlloc * scanAlloc() now returns number of allocated items * Fixed compilation issues related to goto.
This commit is contained in:
@@ -39,13 +39,23 @@ void WiFiClass::scanDelete() {
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::scanAlloc(uint8_t 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;
|
||||
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;
|
||||
}
|
||||
|
||||
String WiFiClass::SSID(uint8_t networkItem) {
|
||||
|
||||
Reference in New Issue
Block a user