-
Notifications
You must be signed in to change notification settings - Fork 3k
Add std::nothrow and null checks to netsocket lib #14223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,6 +377,7 @@ class NetworkInterface: public DNS { | |
*/ | ||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); | ||
|
||
#if MBED_CONF_NSAPI_ADD_EVENT_LISTENER_RETURN_CHANGE | ||
/** Add event listener for interface. | ||
* | ||
* This API allows multiple callback to be registered for a single interface. | ||
|
@@ -387,8 +388,30 @@ class NetworkInterface: public DNS { | |
* of both leads to undefined behavior. | ||
* | ||
* @param status_cb The callback for status changes. | ||
* @return NSAPI_ERROR_OK on success | ||
* @return NSAPI_ERROR_NO_MEMORY if the function fails to create a new entry. | ||
*/ | ||
nsapi_error_t add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); | ||
#else | ||
/** Add event listener for interface. | ||
* | ||
* This API allows multiple callback to be registered for a single interface. | ||
* When first called, internal list of event handlers are created and registered to | ||
* interface through attach() API. | ||
* | ||
* Application may only use attach() or add_event_listener() interface. Mixing usage | ||
* of both leads to undefined behavior. | ||
* | ||
* @warning This version of the function does not use the `std::nothrow` feature. Subsequently, | ||
* the function may fail to allocate memory and cause a system error. To use the new | ||
* version with the changes, set "nsapi.add-event-listener-return-change": 1 in the | ||
* target overrides section in your mbed_app.conf file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
* | ||
* @param status_cb The callback for status changes. | ||
*/ | ||
MBED_DEPRECATED_SINCE("mbed-os-6.8", "This function return value will change to nsapi_error_t in the next major release. See documentation for details.") | ||
void add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); | ||
#endif | ||
|
||
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE | ||
/** Remove event listener from interface. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -982,7 +982,12 @@ static void nsapi_dns_query_async_create(void *ptr) | |
} | ||
|
||
if (!query->socket_cb_data) { | ||
query->socket_cb_data = new SOCKET_CB_DATA; | ||
query->socket_cb_data = new (std::nothrow) SOCKET_CB_DATA; | ||
if (!query->socket_cb_data) { | ||
delete socket; | ||
nsapi_dns_query_async_resp(query, NSAPI_ERROR_NO_MEMORY, NULL); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not return an error ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I won't pretend I understand this portion too much, the function signature here is I did not believe I looked hard enough, however, because I believe that I did not clean up the UDP socket and the appropriate call to the stack created earlier in the same function call. |
||
} | ||
} | ||
query->socket_cb_data->call_in_cb = query->call_in_cb; | ||
query->socket_cb_data->stack = query->stack; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the spellchecker:
add nothrow to mbed-os/tools/test/travis-ci/doxy-spellchecker/ignore.en.pws