Skip to content

Commit 773da3f

Browse files
Yogesh PandeYogesh Pande
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 22acfbf commit 773da3f

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
@@ -31,8 +31,16 @@
3131

3232
#define TRACE_GROUP "mClt"
3333

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

42+
static MemoryPool<M2MConnectionHandlerPimpl::TaskIdentifier, MBED_CLIENT_EVENT_LOOP_SIZE/64> memory_pool;
43+
3644
extern "C" void connection_tasklet_event_handler(arm_event_s *event)
3745
{
3846
tr_debug("M2MConnectionHandlerPimpl::connection_tasklet_event_handler");
@@ -74,7 +82,7 @@ extern "C" void connection_tasklet_event_handler(arm_event_s *event)
7482
break;
7583
}
7684
if (task_id) {
77-
free(task_id);
85+
memory_pool.free(task_id);
7886
}
7987
}
8088

@@ -145,7 +153,7 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
145153
_server_port = server_port;
146154
_server_type = server_type;
147155
_server_address = server_address;
148-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
156+
TaskIdentifier* task = memory_pool.alloc();
149157
if (!task) {
150158
return false;
151159
}
@@ -248,7 +256,7 @@ bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
248256
return false;
249257
}
250258

251-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
259+
TaskIdentifier* task = memory_pool.alloc();
252260
if (!task) {
253261
free(buffer);
254262
return false;
@@ -310,9 +318,7 @@ int8_t M2MConnectionHandlerPimpl::connection_tasklet_handler()
310318

311319
void M2MConnectionHandlerPimpl::socket_event()
312320
{
313-
tr_debug("M2MConnectionHandlerPimpl::socket_event()");
314-
315-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
321+
TaskIdentifier* task = memory_pool.alloc();
316322
if (!task) {
317323
_observer.socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, true);
318324
return;

0 commit comments

Comments
 (0)