diff --git a/src/dird/job.c b/src/dird/job.c index c776a452c3f..74aa06028f5 100644 --- a/src/dird/job.c +++ b/src/dird/job.c @@ -483,7 +483,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); } @@ -491,6 +493,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 75970434cfd..6a554c85c57 100644 --- a/src/dird/migrate.c +++ b/src/dird/migrate.c @@ -1712,11 +1712,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"); }