Skip to content

Commit 5b0f1ca

Browse files
Yogesh Pande0xc0170
authored andcommitted
The original fix was done in ARMmbed/mbed-os-example-client#75 This PR is to merge the fix into mbed-os release candidate.
1 parent 2870ee4 commit 5b0f1ca

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

features/FEATURE_CLIENT/mbed-client-classic/source/m2mconnectionhandlerpimpl.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@
3030

3131
#define TRACE_GROUP "mClt"
3232

33+
#ifdef MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE
34+
#define MBED_CLIENT_EVENT_LOOP_SIZE MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE
35+
#else
36+
#define MBED_CLIENT_EVENT_LOOP_SIZE 1024
37+
#endif
38+
3339
int8_t M2MConnectionHandlerPimpl::_tasklet_id = -1;
3440

41+
static MemoryPool<M2MConnectionHandlerPimpl::TaskIdentifier, MBED_CLIENT_EVENT_LOOP_SIZE/64> memory_pool;
42+
3543
extern "C" void connection_tasklet_event_handler(arm_event_s *event)
3644
{
3745
tr_debug("M2MConnectionHandlerPimpl::connection_tasklet_event_handler");
@@ -73,7 +81,7 @@ extern "C" void connection_tasklet_event_handler(arm_event_s *event)
7381
break;
7482
}
7583
if (task_id) {
76-
free(task_id);
84+
memory_pool.free(task_id);
7785
}
7886
}
7987

@@ -148,7 +156,7 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
148156
_server_port = server_port;
149157
_server_type = server_type;
150158
_server_address = server_address;
151-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
159+
TaskIdentifier* task = memory_pool.alloc();
152160
if (!task) {
153161
return false;
154162
}
@@ -255,7 +263,7 @@ bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
255263
return false;
256264
}
257265

258-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
266+
TaskIdentifier* task = memory_pool.alloc();
259267
if (!task) {
260268
free(buffer);
261269
return false;
@@ -317,9 +325,7 @@ int8_t M2MConnectionHandlerPimpl::connection_tasklet_handler()
317325

318326
void M2MConnectionHandlerPimpl::socket_event()
319327
{
320-
tr_debug("M2MConnectionHandlerPimpl::socket_event()");
321-
322-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
328+
TaskIdentifier* task = memory_pool.alloc();
323329
if (!task) {
324330
_observer.socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, true);
325331
return;

0 commit comments

Comments
 (0)