Merge pull request #13957 from mikaleppanen/new_to_nothrow_mst

Replaced new calls with nothrow version of the call on mesh api
pull/14019/head
Martin Kojtal 2020-12-10 10:59:42 +00:00 committed by GitHub
commit 2c1ce493f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -87,7 +87,7 @@ void ns_event_loop_thread_create(void)
EventQueue *equeue = mbed::mbed_event_queue(); EventQueue *equeue = mbed::mbed_event_queue();
MBED_ASSERT(equeue != NULL); MBED_ASSERT(equeue != NULL);
event = new Event<void()>(equeue, do_dispatch_with_mutex_held); event = new (std::nothrow) Event<void()>(equeue, do_dispatch_with_mutex_held);
MBED_ASSERT(event != NULL); MBED_ASSERT(event != NULL);
} }

View File

@ -71,7 +71,7 @@ enum socket_mode_t {
class NanostackSocket { class NanostackSocket {
public: public:
static void socket_callback(void *cb); static void socket_callback(void *cb);
static void *operator new (std::size_t sz); static void *operator new (std::size_t sz, const std::nothrow_t &nothrow_value) noexcept;
static void operator delete (void *ptr); static void operator delete (void *ptr);
NanostackSocket(int8_t protocol); NanostackSocket(int8_t protocol);
@ -205,10 +205,11 @@ static int nanostack_dns_query_result_check(const char *domain_name, SocketAddre
return -1; return -1;
} }
void *NanostackSocket::operator new (std::size_t sz) void *NanostackSocket::operator new (std::size_t sz, const std::nothrow_t &nothrow_value) noexcept
{ {
return MALLOC(sz); return MALLOC(sz);
} }
void NanostackSocket::operator delete (void *ptr) void NanostackSocket::operator delete (void *ptr)
{ {
FREE(ptr); FREE(ptr);
@ -533,7 +534,7 @@ nsapi_error_t Nanostack::call_in(int delay, mbed::Callback<void()> func)
} }
} }
nanostack_callback *cb = new nanostack_callback; nanostack_callback *cb = new (std::nothrow) nanostack_callback;
if (!cb) { if (!cb) {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
@ -685,7 +686,7 @@ nsapi_error_t Nanostack::socket_open(void **handle, nsapi_protocol_t protocol)
NanostackLockGuard lock; NanostackLockGuard lock;
NanostackSocket *socket = new NanostackSocket(ns_proto); NanostackSocket *socket = new (std::nothrow) NanostackSocket(ns_proto);
if (socket == NULL) { if (socket == NULL) {
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY); tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
@ -1123,7 +1124,7 @@ nsapi_error_t Nanostack::socket_accept(void *server, void **handle, SocketAddres
goto out; goto out;
} }
accepted_sock = new NanostackSocket(socket->proto); accepted_sock = new (std::nothrow) NanostackSocket(socket->proto);
if (accepted_sock == NULL) { if (accepted_sock == NULL) {
ret = NSAPI_ERROR_NO_MEMORY; ret = NSAPI_ERROR_NO_MEMORY;
goto out; goto out;