Fix memory leak in task_queue_add

The task_queue_add function allocates a node but did not free it in the
error case.  Fix this and ensure any future error cases also free the
node.