]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix memory leak for Storage Manager
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Thu, 1 Jul 2021 20:14:39 +0000 (22:14 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:02 +0000 (09:03 +0100)
bacula/src/dird/job.c

index b86dd997b15849632ecea39754302d5110295fb4..6e9391e014bb891d08fbb4ffd5affb4da8f40d5c 100644 (file)
@@ -1624,6 +1624,16 @@ void get_job_storage(USTORE *store, JOB *job, RUN *run)
 /* Init storage manager with specified storage group policy */
 static void init_store_manager(JCR *jcr, const char *policy)
 {
+   if (jcr->store_mngr) {
+      if (strcmp(jcr->store_mngr->get_policy_name(), policy) == 0) {
+         /* Already instantiated manager is of the exact type we need, no work needed here */
+         return;
+      } else {
+         /* Destroy old manager to loose pointer of the previous one since new one will be initialized */
+         delete jcr->store_mngr;
+      }
+   }
+
    if (policy) {
       if (strcmp(policy, "LeastUsed") == 0) {
          Dmsg1(dbglvl_store_mngr, "Setting LeastUsed storage group policy for JobId: %d\n", jcr->JobId);