Merge pull request #12399 from kivaisan/delete_context_if_activation_fails

Cellular: Delete created context if activation fails
pull/12405/head
Martin Kojtal 2020-02-10 14:21:30 +00:00 committed by GitHub
commit 94e191f57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 13 deletions

View File

@ -530,21 +530,17 @@ nsapi_error_t AT_CellularContext::find_and_activate_context()
}
if (err != NSAPI_ERROR_OK) {
_at.unlock();
tr_error("Failed to activate network context! (%d)", err);
return err;
}
} else if (!(_nonip_req && _cp_in_use) && !get_stack()) {
// do check for stack to validate that we have support for stack
if (!(_nonip_req && _cp_in_use) && !get_stack()) {
_at.unlock();
tr_error("No cellular stack!");
return NSAPI_ERROR_UNSUPPORTED;
err = NSAPI_ERROR_UNSUPPORTED;
}
_is_context_active = false;
_is_context_activated = false;
if (err == NSAPI_ERROR_OK) {
_is_context_active = _nw->is_active_context(NULL, _cid);
if (!_is_context_active) {
@ -552,6 +548,7 @@ nsapi_error_t AT_CellularContext::find_and_activate_context()
}
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
}
// If new PDP context was created and failed to activate, delete it
if (err != NSAPI_ERROR_OK && _new_context_set) {