Skip to content

Commit 94e191f

Browse files
authored
Merge pull request #12399 from kivaisan/delete_context_if_activation_fails
Cellular: Delete created context if activation fails
2 parents 88438df + 2b19fd8 commit 94e191f

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,28 +530,25 @@ nsapi_error_t AT_CellularContext::find_and_activate_context()
530530
}
531531

532532
if (err != NSAPI_ERROR_OK) {
533-
_at.unlock();
534533
tr_error("Failed to activate network context! (%d)", err);
535-
return err;
536-
}
537-
538-
// do check for stack to validate that we have support for stack
539-
if (!(_nonip_req && _cp_in_use) && !get_stack()) {
540-
_at.unlock();
534+
} else if (!(_nonip_req && _cp_in_use) && !get_stack()) {
535+
// do check for stack to validate that we have support for stack
541536
tr_error("No cellular stack!");
542-
return NSAPI_ERROR_UNSUPPORTED;
537+
err = NSAPI_ERROR_UNSUPPORTED;
543538
}
544539

545540
_is_context_active = false;
546541
_is_context_activated = false;
547542

548-
_is_context_active = _nw->is_active_context(NULL, _cid);
543+
if (err == NSAPI_ERROR_OK) {
544+
_is_context_active = _nw->is_active_context(NULL, _cid);
549545

550-
if (!_is_context_active) {
551-
activate_context();
552-
}
546+
if (!_is_context_active) {
547+
activate_context();
548+
}
553549

554-
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
550+
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
551+
}
555552

556553
// If new PDP context was created and failed to activate, delete it
557554
if (err != NSAPI_ERROR_OK && _new_context_set) {

0 commit comments

Comments
 (0)