add execption check after malloc

This commit is contained in:
dkang 2018-11-14 17:00:51 +09:00 committed by Beat Küng
parent 7779c0bd69
commit 4901f8a1dc
No known key found for this signature in database
GPG Key ID: 866DB5F0E24821BB
2 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

@ -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;