Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2d83e5

Browse filesBrowse files
committed
[WiFiScan] Allow allocation to fail and prevent memory leak
When there are many AP's seen during a scan, the allocation of `_scanResult` may fail. Thus add `(std::nothrow)` to the `new` call. Also it is possible the array was still present before allocating a new one.
1 parent 4e9eb35 commit f2d83e5
Copy full SHA for f2d83e5

File tree

Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed

‎libraries/WiFi/src/WiFiScan.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiScan.cpp
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ int16_t
117117
*/
118118
void WiFiScanClass::_scanDone() {
119119
esp_wifi_scan_get_ap_num(&(WiFiScanClass::_scanCount));
120+
if (WiFiScanClass::_scanResult) {
121+
delete[] reinterpret_cast<wifi_ap_record_t *>(WiFiScanClass::_scanResult);
122+
WiFiScanClass::_scanResult = 0;
123+
}
124+
120125
if (WiFiScanClass::_scanCount) {
121-
WiFiScanClass::_scanResult = new wifi_ap_record_t[WiFiScanClass::_scanCount];
126+
WiFiScanClass::_scanResult = new (std::nothrow) wifi_ap_record_t[WiFiScanClass::_scanCount];
122127
if (!WiFiScanClass::_scanResult) {
123128
WiFiScanClass::_scanCount = 0;
124129
} else if (esp_wifi_scan_get_ap_records(&(WiFiScanClass::_scanCount), (wifi_ap_record_t *)_scanResult) != ESP_OK) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.