ike_sa: Defer task manager destruction after child destruction
[strongswan.git] / src / libcharon / sa / ikev1 / task_manager_v1.c
index d97ef0e..131d812 100644 (file)
@@ -339,10 +339,8 @@ METHOD(task_manager_t, flush_queue, void,
        }
 }
 
-/**
- * flush all tasks in the task manager
- */
-static void flush(private_task_manager_t *this)
+METHOD(task_manager_t, flush, void,
+       private_task_manager_t *this)
 {
        flush_queue(this, TASK_QUEUE_QUEUED);
        flush_queue(this, TASK_QUEUE_PASSIVE);
@@ -1273,7 +1271,7 @@ static status_t handle_fragment(private_task_manager_t *this, message_t *msg)
                return FAILED;
        }
 
-       if (this->frag.id != payload->get_id(payload))
+       if (!this->frag.list || this->frag.id != payload->get_id(payload))
        {
                clear_fragments(this, payload->get_id(payload));
                this->frag.list = linked_list_create();
@@ -1785,7 +1783,7 @@ static bool have_equal_ts(child_sa_t *child1, child_sa_t *child2, bool local)
        {
                equal = ts1->equals(ts1, ts2);
        }
-       e1->destroy(e1);
+       e2->destroy(e2);
        e1->destroy(e1);
 
        return equal;
@@ -2070,6 +2068,7 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
                                .adopt_child_tasks = _adopt_child_tasks,
                                .busy = _busy,
                                .create_task_enumerator = _create_task_enumerator,
+                               .flush = _flush,
                                .flush_queue = _flush_queue,
                                .destroy = _destroy,
                        },