1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-07 06:01:35 +03:00

replace new by new (std::nothrow), remove arduino_new

This commit is contained in:
david gauchard
2020-08-17 18:15:45 +02:00
parent 5b3d290de8
commit 6925982284
45 changed files with 207 additions and 167 deletions

View File

@ -109,7 +109,7 @@ namespace brssl {
}
static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc) {
std::unique_ptr<br_x509_decoder_context> dc(new br_x509_decoder_context); // auto-delete on exit
std::unique_ptr<br_x509_decoder_context> dc(new (std::nothrow) br_x509_decoder_context); // auto-delete on exit
std::vector<uint8_t> vdn;
br_x509_pkey *pk;
@ -244,7 +244,7 @@ namespace brssl {
// blobs may be returned.
pem_object *decode_pem(const void *src, size_t len, size_t *num) {
std::vector<pem_object> pem_list;
std::unique_ptr<br_pem_decoder_context> pc(new br_pem_decoder_context); // auto-delete on exit
std::unique_ptr<br_pem_decoder_context> pc(new (std::nothrow) br_pem_decoder_context); // auto-delete on exit
if (!pc.get()) {
return nullptr;
}
@ -405,7 +405,7 @@ namespace brssl {
}
static public_key *decode_public_key(const unsigned char *buff, size_t len) {
std::unique_ptr<br_pkey_decoder_context> dc(new br_pkey_decoder_context); // auto-delete on exit
std::unique_ptr<br_pkey_decoder_context> dc(new (std::nothrow) br_pkey_decoder_context); // auto-delete on exit
if (!dc.get()) {
return nullptr;
}
@ -477,7 +477,7 @@ namespace brssl {
}
static private_key *decode_private_key(const unsigned char *buff, size_t len) {
std::unique_ptr<br_skey_decoder_context> dc(new br_skey_decoder_context); // auto-delete on exit
std::unique_ptr<br_skey_decoder_context> dc(new (std::nothrow) br_skey_decoder_context); // auto-delete on exit
if (!dc.get()) {
return nullptr;
}

View File

@ -50,9 +50,13 @@ CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset,
memset(&ci, 0, sizeof(ci));
// Process it using SHA256, same as the hashed_dn
br_x509_decoder_context *ctx = new br_x509_decoder_context;
br_sha256_context *sha256 = new br_sha256_context;
br_x509_decoder_context *ctx = new (std::nothrow) br_x509_decoder_context;
br_sha256_context *sha256 = new (std::nothrow) br_sha256_context;
if (!ctx || !sha256) {
if (ctx)
delete ctx;
if (sha256)
delete sha256;
DEBUG_BSSL("CertStore::_preprocessCert: OOM\n");
return ci;
}
@ -202,7 +206,7 @@ const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn,
return nullptr;
}
data.close();
cs->_x509 = new X509List(der, ci.length);
cs->_x509 = new (std::nothrow) X509List(der, ci.length);
free(der);
if (!cs->_x509) {
DEBUG_BSSL("CertStore::findHashedTA: OOM\n");

View File

@ -308,7 +308,10 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
if(i == 0) {
ESP8266WiFiScanClass::_scanResult = 0;
} else {
bss_info* copied_info = new bss_info[i];
bss_info* copied_info = new (std::nothrow) bss_info[i];
if (copied_info == nullptr) {
return;
}
i = 0;
for(bss_info* it = head; it; it = STAILQ_NEXT(it, next), ++i) {
memcpy(copied_info + i, it, sizeof(bss_info));

View File

@ -153,7 +153,10 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
pcb->local_port = _localPort++;
}
_client = new ClientContext(pcb, nullptr, nullptr);
_client = new (std::nothrow) ClientContext(pcb, nullptr, nullptr);
if (_client == nullptr) {
return 0;
}
_client->ref();
_client->setTimeout(_timeout);
int res = _client->connect(ip, port);

View File

@ -977,7 +977,7 @@ extern "C" {
// Set custom list of ciphers
bool WiFiClientSecure::setCiphers(const uint16_t *cipherAry, int cipherCount) {
_cipher_list = nullptr;
_cipher_list = std::shared_ptr<uint16_t>(new uint16_t[cipherCount], std::default_delete<uint16_t[]>());
_cipher_list = std::shared_ptr<uint16_t>(new (std::nothrow) uint16_t[cipherCount], std::default_delete<uint16_t[]>());
if (!_cipher_list.get()) {
DEBUG_BSSL("setCiphers: list empty\n");
return false;
@ -1067,8 +1067,8 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
_sc = std::make_shared<br_ssl_client_context>();
_eng = &_sc->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc || !_iobuf_in || !_iobuf_out) {
_freeSSL(); // Frees _sc, _iobuf*
@ -1183,8 +1183,8 @@ bool WiFiClientSecure::_connectSSLServerRSA(const X509List *chain,
_oom_err = false;
_sc_svr = std::make_shared<br_ssl_server_context>();
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
_freeSSL();
@ -1220,8 +1220,8 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
_oom_err = false;
_sc_svr = std::make_shared<br_ssl_server_context>();
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
_freeSSL();
@ -1421,7 +1421,7 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
default: return false; // Invalid size
}
int ttlLen = sizeof(clientHelloHead_P) + (2 + sizeof(suites_P)) + (sizeof(clientHelloTail_P) + 1);
uint8_t *clientHello = new uint8_t[ttlLen];
uint8_t *clientHello = new (std::nothrow) uint8_t[ttlLen];
if (!clientHello) {
DEBUG_BSSL("probeMaxFragmentLength: OOM\n");
return false;
@ -1580,21 +1580,21 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
// AXTLS compatibility interfaces
bool WiFiClientSecure::setCACert(const uint8_t* pk, size_t size) {
_axtls_ta = nullptr;
_axtls_ta = std::shared_ptr<X509List>(new X509List(pk, size));
_axtls_ta = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
_ta = _axtls_ta.get();
return _ta ? true : false;
}
bool WiFiClientSecure::setCertificate(const uint8_t* pk, size_t size) {
_axtls_chain = nullptr;
_axtls_chain = std::shared_ptr<X509List>(new X509List(pk, size));
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
_chain = _axtls_chain.get();
return _chain ? true : false;
}
bool WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size) {
_axtls_sk = nullptr;
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(pk, size));
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(pk, size));
_sk = _axtls_sk.get();
return _sk ? true : false;

View File

@ -186,7 +186,10 @@ long WiFiServer::_accept(tcp_pcb* apcb, long err) {
// always accept new PCB so incoming data can be stored in our buffers even before
// user calls ::available()
ClientContext* client = new ClientContext(apcb, &WiFiServer::_s_discard, this);
ClientContext* client = new (std::nothrow) ClientContext(apcb, &WiFiServer::_s_discard, this);
if (client == nullptr) {
return ERR_MEM;
}
// backlog doc:
// http://lwip.100.n7.nabble.com/Problem-re-opening-listening-pbc-tt32484.html#a32494

View File

@ -107,8 +107,8 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
void WiFiServerSecure::setServerKeyAndCert(const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) {
_axtls_chain = nullptr;
_axtls_sk = nullptr;
_axtls_chain = std::shared_ptr<X509List>(new X509List(cert, certLen));
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(key, keyLen));
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(cert, certLen));
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(key, keyLen));
setRSACert(_axtls_chain.get(), _axtls_sk.get());
}

View File

@ -80,7 +80,10 @@ uint8_t WiFiUDP::begin(uint16_t port)
_ctx = 0;
}
_ctx = new UdpContext;
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx->ref();
return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
}
@ -96,7 +99,10 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
return 0;
}
_ctx = new UdpContext;
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx->ref();
ip_addr_t addr = IPADDR4_INIT(INADDR_ANY);
if (!_ctx->listen(&addr, port)) {
@ -147,7 +153,10 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port)
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
{
if (!_ctx) {
_ctx = new UdpContext;
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx->ref();
}
return (_ctx->connect(ip, port)) ? 1 : 0;
@ -157,7 +166,10 @@ int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
IPAddress interfaceAddress, int ttl)
{
if (!_ctx) {
_ctx = new UdpContext;
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx->ref();
}
if (!_ctx->connect(multicastAddress, port)) {

View File

@ -374,7 +374,7 @@ public:
if (!_pcb) {
return 0;
}
return _write_from_source(new BufferDataSource(data, size));
return _write_from_source(new (std::nothrow) BufferDataSource(data, size));
}
size_t write(Stream& stream)
@ -382,7 +382,7 @@ public:
if (!_pcb) {
return 0;
}
return _write_from_source(new BufferedStreamDataSource<Stream>(stream, stream.available()));
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<Stream>(stream, stream.available()));
}
size_t write_P(PGM_P buf, size_t size)
@ -391,7 +391,7 @@ public:
return 0;
}
ProgmemStream stream(buf, size);
return _write_from_source(new BufferedStreamDataSource<ProgmemStream>(stream, size));
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<ProgmemStream>(stream, size));
}
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)

View File

@ -75,7 +75,7 @@ public:
//Buffer too small?
if (_bufferSize < min_buffer_size) {
uint8_t *new_buffer = new uint8_t[min_buffer_size];
uint8_t *new_buffer = new (std::nothrow) uint8_t[min_buffer_size];
//If stream reading is ahead, than some data is already in the old buffer and needs to be copied to new resized buffer
if (_buffer && stream_read > 0) {
memcpy(new_buffer, _buffer.get(), stream_read);