diff --git a/src/dird/job.c b/src/dird/job.c index aa14f0ac4b8..77a193dfa99 100644 --- a/src/dird/job.c +++ b/src/dird/job.c @@ -475,7 +475,9 @@ static void *job_thread(void *arg) run_scripts(jcr, jcr->res.job->RunScripts, "AfterJob"); - /* Send off any queued messages */ + /* + * Send off any queued messages + */ if (jcr->msg_queue && jcr->msg_queue->size() > 0) { dequeue_messages(jcr); } @@ -483,6 +485,16 @@ static void *job_thread(void *arg) generate_plugin_event(jcr, bDirEventJobEnd); Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus); Dsm_check(100); + + /* + * If we have a migration JCR now is the correct time to detach it + * as we are done running. + */ + if (jcr->mig_jcr) { + free_jcr(jcr->mig_jcr); + jcr->mig_jcr = NULL; + } + return NULL; } diff --git a/src/dird/migrate.c b/src/dird/migrate.c index 098bca90af2..7a8e20c0f9c 100644 --- a/src/dird/migrate.c +++ b/src/dird/migrate.c @@ -1427,11 +1427,6 @@ void migration_cleanup(JCR *jcr, int TermCode) sd_term_msg, term_code); - Dmsg1(100, "migrate_cleanup() mig_jcr=0x%x\n", jcr->mig_jcr); - if (jcr->mig_jcr) { - free_jcr(jcr->mig_jcr); - jcr->mig_jcr = NULL; - } Dmsg0(100, "Leave migrate_cleanup()\n"); }