diff --git a/platforms/posix/src/px4_layer/px4_posix_tasks.cpp b/platforms/posix/src/px4_layer/px4_posix_tasks.cpp index 607d5071b9..ff3bf3aa49 100644 --- a/platforms/posix/src/px4_layer/px4_posix_tasks.cpp +++ b/platforms/posix/src/px4_layer/px4_posix_tasks.cpp @@ -144,6 +144,11 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int // not safe to pass stack data to the thread creation pthdata_t *taskdata = (pthdata_t *)malloc(structsize + len); + + if (taskdata == nullptr) { + return -ENOMEM; + } + memset(taskdata, 0, structsize + len); unsigned long offset = ((unsigned long)taskdata) + structsize; diff --git a/platforms/qurt/src/px4_layer/px4_qurt_tasks.cpp b/platforms/qurt/src/px4_layer/px4_qurt_tasks.cpp index 5d1093159d..e6c8e191e8 100644 --- a/platforms/qurt/src/px4_layer/px4_qurt_tasks.cpp +++ b/platforms/qurt/src/px4_layer/px4_qurt_tasks.cpp @@ -147,6 +147,11 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int // not safe to pass stack data to the thread creation taskdata = (pthdata_t *)malloc(structsize + len); + + if (taskdata == nullptr) { + return -ENOMEM; + } + offset = ((unsigned long)taskdata) + structsize; taskdata->entry = entry;