esp8266/modnetwork: Protect scan() callback against memory errors.

scan() allocates memory so may cause an exception to be raised.
pull/2121/merge
Damien George 2016-05-29 09:52:07 +01:00
rodzic 55df14f1a4
commit 84381fa0fc
1 zmienionych plików z 19 dodań i 10 usunięć

Wyświetl plik

@ -136,6 +136,9 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) {
return;
}
if (si->pbss && status == 0) {
// we need to catch any memory errors
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
struct bss_info *bs;
STAILQ_FOREACH(bs, si->pbss, next) {
mp_obj_tuple_t *t = mp_obj_new_tuple(6, NULL);
@ -147,6 +150,12 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) {
t->items[5] = MP_OBJ_NEW_SMALL_INT(bs->is_hidden);
mp_obj_list_append(*esp_scan_list, MP_OBJ_FROM_PTR(t));
}
nlr_pop();
} else {
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
// indicate error
*esp_scan_list = MP_OBJ_NULL;
}
} else {
// indicate error
*esp_scan_list = MP_OBJ_NULL;