diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index 00cb46f88b28..4be29f583ee5 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -130,14 +130,16 @@ _taskqueue_create(const char *name, int mflags, char *tq_name; tq_name = malloc(TASKQUEUE_NAMELEN, M_TASKQUEUE, mflags | M_ZERO); - if (!tq_name) + if (tq_name == NULL) return (NULL); - snprintf(tq_name, TASKQUEUE_NAMELEN, "%s", (name) ? name : "taskqueue"); - queue = malloc(sizeof(struct taskqueue), M_TASKQUEUE, mflags | M_ZERO); - if (!queue) + if (queue == NULL) { + free(tq_name, M_TASKQUEUE); return (NULL); + } + + snprintf(tq_name, TASKQUEUE_NAMELEN, "%s", (name) ? name : "taskqueue"); STAILQ_INIT(&queue->tq_queue); TAILQ_INIT(&queue->tq_active);