processor: Flush pending jobs during cancel(), not destroy
authorMartin Willi <martin@revosec.ch>
Tue, 11 Feb 2014 14:41:49 +0000 (15:41 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 7 May 2014 12:13:34 +0000 (14:13 +0200)
During shutdown, cancel queued jobs earlier to avoid having cleanup functions
accessing infrastructure not available anymore, for example watcher.

src/libstrongswan/processing/processor.c

index 012b169..27e5ab5 100644 (file)
@@ -467,6 +467,8 @@ METHOD(processor_t, cancel, void,
 {
        enumerator_t *enumerator;
        worker_thread_t *worker;
+       job_t *job;
+       int i;
 
        this->mutex->lock(this->mutex);
        this->desired_threads = 0;
@@ -496,6 +498,14 @@ METHOD(processor_t, cancel, void,
                worker->thread->join(worker->thread);
                free(worker);
        }
+       for (i = 0; i < JOB_PRIO_MAX; i++)
+       {
+               while (this->jobs[i]->remove_first(this->jobs[i],
+                                                                                  (void**)&job) == SUCCESS)
+               {
+                       job->destroy(job);
+               }
+       }
        this->mutex->unlock(this->mutex);
 }
 
@@ -510,7 +520,7 @@ METHOD(processor_t, destroy, void,
        this->mutex->destroy(this->mutex);
        for (i = 0; i < JOB_PRIO_MAX; i++)
        {
-               this->jobs[i]->destroy_offset(this->jobs[i], offsetof(job_t, destroy));
+               this->jobs[i]->destroy(this->jobs[i]);
        }
        this->threads->destroy(this->threads);
        free(this);