housekeeper: Copy data to prevent access of freed data

This commit is contained in:
Johan Wikman 2016-09-29 09:34:35 +03:00
parent 4df5431572
commit 3d5cfee348

View File

@ -275,11 +275,16 @@ hkthread(void *data)
ptr->nextdue = now + ptr->frequency;
taskfn = ptr->task;
taskdata = ptr->data;
// We need to copy type and name, in case hktask_remove is called from
// the callback. Otherwise we will access freed data.
HKTASK_TYPE type = ptr->type;
char name[strlen(ptr->name) + 1];
strcpy(name, ptr->name);
spinlock_release(&tasklock);
(*taskfn)(taskdata);
if (ptr->type == HK_ONESHOT)
if (type == HK_ONESHOT)
{
hktask_remove(ptr->name);
hktask_remove(name);
}
spinlock_acquire(&tasklock);
ptr = tasks;