Skip to content

Commit 8ad0335

Browse files
WIP
1 parent 46a503c commit 8ad0335

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

libraries/BLE/src/BLEAdvertising.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ void BLEAdvertising::start() {
193193
int numServices = m_serviceUUIDs.size();
194194
if (numServices > 0) {
195195
m_advData.service_uuid_len = 16 * numServices;
196-
m_advData.p_service_uuid = new uint8_t[m_advData.service_uuid_len];
196+
m_advData.p_service_uuid = (uint8_t *)malloc(m_advData.service_uuid_len);
197+
if(!m_advData.p_service_uuid) {
198+
log_e(">> start failed: out of memory");
199+
return;
200+
}
201+
197202
uint8_t* p = m_advData.p_service_uuid;
198203
for (int i = 0; i < numServices; i++) {
199204
log_d("- advertising service: %s", m_serviceUUIDs[i].toString().c_str());
@@ -238,10 +243,8 @@ void BLEAdvertising::start() {
238243

239244
// If we had services to advertise then we previously allocated some storage for them.
240245
// Here we release that storage.
241-
if (m_advData.service_uuid_len > 0) {
242-
delete[] m_advData.p_service_uuid;
243-
m_advData.p_service_uuid = nullptr;
244-
}
246+
free(m_advData.p_service_uuid); //TODO change this variable to local scope?
247+
m_advData.p_service_uuid = nullptr;
245248

246249
// Start advertising.
247250
errRc = ::esp_ble_gap_start_advertising(&m_advParams);

libraries/WebServer/src/WebServer.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <Arduino.h>
2525
#include <esp32-hal-log.h>
2626
#include <libb64/cencode.h>
27-
#include <new>
2827
#include "WiFiServer.h"
2928
#include "WiFiClient.h"
3029
#include "WebServer.h"
@@ -146,26 +145,26 @@ bool WebServer::authenticate(const char * username, const char * password){
146145
authReq = authReq.substring(6);
147146
authReq.trim();
148147
char toencodeLen = strlen(username)+strlen(password)+1;
149-
char *toencode = new(std::nothrow) char[toencodeLen + 1];
148+
char *toencode = (char *)malloc[toencodeLen + 1];
150149
if(toencode == NULL){
151150
authReq = "";
152151
return false;
153152
}
154-
char *encoded = new(std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
153+
char *encoded = (char *)malloc(base64_encode_expected_len(toencodeLen)+1);
155154
if(encoded == NULL){
156155
authReq = "";
157-
delete[] toencode;
156+
free(toencode);
158157
return false;
159158
}
160159
sprintf(toencode, "%s:%s", username, password);
161160
if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equalsConstantTime(encoded)) {
162161
authReq = "";
163-
delete[] toencode;
164-
delete[] encoded;
162+
free(toencode);
163+
free(encoded);
165164
return true;
166165
}
167-
delete[] toencode;
168-
delete[] encoded;
166+
free(toencode);
167+
free(encoded);;
169168
} else if(authReq.startsWith(F("Digest"))) {
170169
authReq = authReq.substring(7);
171170
log_v("%s", authReq.c_str());

libraries/WiFi/src/WiFiUdp.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ uint8_t WiFiUDP::begin(IPAddress address, uint16_t port){
4444

4545
server_port = port;
4646

47-
tx_buffer = new(std::nothrow) char[1460];
47+
tx_buffer = (char *)malloc(1460);
4848
if(!tx_buffer){
4949
log_e("could not create tx buffer: %d", errno);
5050
return 0;
5151
}
52+
tx_buffer_len = 0;
5253

5354
if ((udp_server=socket(AF_INET, SOCK_DGRAM, 0)) == -1){
5455
log_e("could not create socket: %d", errno);
@@ -100,7 +101,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress a, uint16_t p){
100101

101102
void WiFiUDP::stop(){
102103
if(tx_buffer){
103-
delete[] tx_buffer;
104+
free(tx_buffer);
104105
tx_buffer = NULL;
105106
}
106107
tx_buffer_len = 0;
@@ -136,13 +137,12 @@ int WiFiUDP::beginPacket(){
136137

137138
// allocate tx_buffer if is necessary
138139
if(!tx_buffer){
139-
tx_buffer = new(std::nothrow) char[1460];
140+
tx_buffer = (char *)malloc(1460);
140141
if(!tx_buffer){
141142
log_e("could not create tx buffer: %d", errno);
142143
return 0;
143144
}
144145
}
145-
146146
tx_buffer_len = 0;
147147

148148
// check whereas socket is already open

0 commit comments

Comments
 (0)