Fix 'netsocket: several dynamic allocation results not checked' (#14210) #14740
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Copied from #14706)
Summary of changes
This changes adds
std::nowthrow
and the checks for allocation failure to all places in thenetsocket
portion that lacked it. This change addresses #14210.Impact of changes
add_event_listener
inNetworkInterface
now returns an error if the method fails. Previous attempts to add the event listener would attempt to use an unchecked standard dynamically allocatedns_list_*
item.In other cases, the dynamically allocated items will now be checked, and if unsuccessful, will return after cleaning up any outstanding issues.
TCPSocket::accept
will now check that its own internally allocatednew TCPSocket
call will succeed, and if not, will clean up the stack resources. This should help when memory is low but an incoming connection requests a connection when theTCPSocket
is listening.Migration actions required
As
new
calls are now handled, code that did not check against this failure may now check for failure and handle it at the application layer.add_event_listener
now returnsnsapi_error_t
instead ofvoid
. The two return values possible areNSAPI_ERROR_OK
andNSAPI_ERROR_NO_MEMORY
in the case of memory allocation failure.Documentation
NetworkInterface.h
now has changes to theadd_event_listener
method. This method will now returnnsapi_error_t
instead ofvoid
. The docstring for the interface has been updated.Pull request type
Test results
Reviewers