]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Change edit_device_codes() prototype to avoid POOLMEM leaks
authornorbert.bizet <norbert.bizet@baculasystems.com>
Wed, 12 Oct 2022 15:46:10 +0000 (11:46 -0400)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
bacula/src/stored/autochanger.c
bacula/src/stored/btape.c
bacula/src/stored/protos.h
bacula/src/stored/sd_plugins.c
bacula/src/stored/sd_plugins.h
bacula/src/stored/tape_alert.c
bacula/src/stored/tape_worm.c

index 71256b79257d1c8d38a2f25146eb8afaed0ac156..c1002e1f4fa0daa9a480f3134f7cf232a773cd14 100644 (file)
@@ -197,7 +197,7 @@ int autoload_device(DCR *dcr, bool writing, BSOCK *dir)
             new_vol_name, slot, drive);
 
          dcr->VolCatInfo.Slot = slot;    /* slot to be loaded */
-         changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "load");
+         edit_device_codes(dcr, &changer, dcr->device->changer_command, "load");
          dev->close(dcr);
          Dmsg1(dbglvl, "Run program=%s\n", changer);
          status = run_program_full_output(changer, timeout, results.addr());
@@ -284,7 +284,7 @@ int get_autochanger_loaded_slot(DCR *dcr)
       Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded? drive %d\" command.\n"),
            drive);
    }
-   changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "loaded");
+   edit_device_codes(dcr, &changer, dcr->device->changer_command, "loaded");
    Dmsg1(dbglvl, "Run program=%s\n", changer);
    status = run_program_full_output(changer, timeout, results.addr());
    Dmsg3(dbglvl, "run_prog: %s stat=%d result=%s", changer, status, results.c_str());
@@ -406,7 +406,7 @@ bool unload_autochanger(DCR *dcr, int loaded)
          old_vol_name, loaded, dev->drive_index);
       slot = dcr->VolCatInfo.Slot;
       dcr->VolCatInfo.Slot = loaded;
-      changer = edit_device_codes(dcr, changer,
+      edit_device_codes(dcr, &changer,
                    dcr->device->changer_command, "unload");
       dev->close(dcr);
       Dmsg1(dbglvl, "Run program=%s\n", changer);
@@ -590,8 +590,7 @@ bool unload_dev(DCR *dcr, DEVICE *dev)
    Dmsg3(0/*dbglvl*/, "Issuing autochanger \"unload Volume %s, Slot %d, Drive %d\" command.\n",
         old_vol_name, dev->get_slot(), dev->drive_index);
 
-   changer_cmd = edit_device_codes(dcr, changer_cmd,
-                dcr->device->changer_command, "unload");
+   edit_device_codes(dcr, &changer_cmd, dcr->device->changer_command, "unload");
    dev->close(dcr);
    Dmsg2(dbglvl, "close dev=%s reserve=%d\n", dev->print_name(),
       dev->num_reserved());
@@ -671,8 +670,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
    changer = get_pool_memory(PM_FNAME);
    lock_changer(dcr);
    /* Now issue the command */
-   changer = edit_device_codes(dcr, changer,
-                 dcr->device->changer_command, cmd);
+   edit_device_codes(dcr, &changer, dcr->device->changer_command, cmd);
    dir->fsend(_("3306 Issuing autochanger \"%s\" command.\n"), cmd);
    bpipe = open_bpipe(changer, timeout, "r");
    if (!bpipe) {
@@ -733,7 +731,7 @@ bail_out:
  *  cmd = command string (load, unload, ...)
  *
  */
-char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd)
+void edit_device_codes(DCR *dcr, POOLMEM **omsg, const char *imsg, const char *cmd)
 {
    const char *p;
    const char *str;
@@ -804,9 +802,8 @@ char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd)
          str = add;
       }
       Dmsg1(1900, "add_str %s\n", str);
-      pm_strcat(&omsg, (char *)str);
+      pm_strcat(omsg, (char *)str);
       Dmsg1(1800, "omsg=%s\n", omsg);
    }
    Dmsg1(800, "omsg=%s\n", omsg);
-   return omsg;
 }
index fd172182fb5114bed1b87b58740ab0b80482d1b6..f31f1cc5fd3aa17ce4df7fb99783a7bad4930764 100644 (file)
@@ -1495,8 +1495,7 @@ try_again:
    dcr->VolCatInfo.Slot = slot;
    /* Find out what is loaded, zero means device is unloaded */
    Pmsg0(-1, _("3301 Issuing autochanger \"loaded\" command.\n"));
-   changer = edit_device_codes(dcr, changer,
-                dcr->device->changer_command, "loaded");
+   edit_device_codes(dcr, &changer, dcr->device->changer_command, "loaded");
    status = run_program(changer, timeout, results);
    Dmsg3(100, "run_prog: %s stat=%d result=\"%s\"\n", changer, status, results);
    if (status == 0) {
@@ -1519,8 +1518,7 @@ try_again:
       dev->close(dcr);
       Pmsg2(-1, _("3302 Issuing autochanger \"unload %d %d\" command.\n"),
          loaded, dev->drive_index);
-      changer = edit_device_codes(dcr, changer,
-                   dcr->device->changer_command, "unload");
+      edit_device_codes(dcr, &changer, dcr->device->changer_command, "unload");
       status = run_program(changer, timeout, results);
       Pmsg2(-1, _("unload status=%s %d\n"), status==0?_("OK"):_("Bad"), status);
       if (status != 0) {
@@ -1538,8 +1536,7 @@ try_again:
    dcr->VolCatInfo.Slot = slot;
    Pmsg2(-1, _("3303 Issuing autochanger \"load %d %d\" command.\n"),
       slot, dev->drive_index);
-   changer = edit_device_codes(dcr, changer,
-                dcr->device->changer_command, "load");
+   edit_device_codes(dcr, &changer, dcr->device->changer_command, "load");
    Dmsg1(100, "Changer=%s\n", changer);
    dev->close(dcr);
    status = run_program(changer, timeout, results);
index 21293224adff37248c3f828f9c01724f539c5363..1ebc8c330bfac53bd3d2301f0eafca5d73fd939e 100644 (file)
@@ -110,7 +110,7 @@ int      autoload_device(DCR *dcr, bool writing, BSOCK *dir);
 bool     autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
 bool     unload_autochanger(DCR *dcr, int loaded);
 bool     unload_dev(DCR *dcr, DEVICE *dev);
-char    *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
+void     edit_device_codes(DCR *dcr, POOLMEM **omsg, const char *imsg, const char *cmd);
 int      get_autochanger_loaded_slot(DCR *dcr);
 
 /* From block.c */
index c42231845971605c83a897245bc3b8bd9313a96a..f5efd47a935fe2010293a0dad44f8b56e20b22d7 100644 (file)
@@ -39,7 +39,7 @@ static bRC baculaJobMsg(bpContext *ctx, const char *file, int line,
   int type, utime_t mtime, const char *fmt, ...);
 static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line,
   int level, const char *fmt, ...);
-static char *baculaEditDeviceCodes(DCR *dcr, char *omsg,
+static void baculaEditDeviceCodes(DCR *dcr, POOLMEM **omsg,
   const char *imsg, const char *cmd);
 static bool is_plugin_compatible(Plugin *plugin);
 
@@ -465,10 +465,10 @@ static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line,
    return bRC_OK;
 }
 
-static char *baculaEditDeviceCodes(DCR *dcr, char *omsg,
+static void baculaEditDeviceCodes(DCR *dcr, POOLMEM **omsg,
   const char *imsg, const char *cmd)
 {
-   return edit_device_codes(dcr, omsg, imsg, cmd);
+   edit_device_codes(dcr, omsg, imsg, cmd);
 }
 
 #ifdef TEST_PROGRAM
index e377840d974ad4a53a506b67c874f8156c8cdfd1..3db8645048b453aec3e72faa9a896d84dda432ae 100644 (file)
@@ -135,7 +135,7 @@ typedef struct s_sdbaculaFuncs {
        int type, utime_t mtime, const char *fmt, ...);
    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
        int level, const char *fmt, ...);
-   char *(*EditDeviceCodes)(DCR *dcr, char *omsg,
+   void (*EditDeviceCodes)(DCR *dcr, POOLMEM **omsg,
        const char *imsg, const char *cmd);
    bRC (*getBaculaGlobal)(bsdrGlobalVariable var, void *value); /* ***BEEF*** */
 } bsdFuncs;
index f5c24988a8ae5f02463121ae9dd31c8691d65ef8..5cadb482f4e5b22413492159c512ab106f0f21e8 100644 (file)
@@ -99,7 +99,7 @@ bool tape_dev::get_tape_alerts(DCR *dcr)
          alert_list = New(alist(10));
       }
       alertcmd = get_pool_memory(PM_FNAME);
-      alertcmd = edit_device_codes(dcr, alertcmd, dcr->device->alert_command, "");
+      edit_device_codes(dcr, &alertcmd, dcr->device->alert_command, "");
       /* Wait maximum 5 minutes */
       bpipe = open_bpipe(alertcmd, 60 * 5, "r");
       if (bpipe) {
index e4ef6c8646938d56332133cb64248f50fcf21d80..f20792b2f081911498db9416ac3a7cd843059c54 100644 (file)
@@ -46,7 +46,7 @@ bool tape_dev::get_tape_worm(DCR *dcr)
       const char *fmt = " %d";
 
       wormcmd = get_pool_memory(PM_FNAME);
-      wormcmd = edit_device_codes(dcr, wormcmd, dcr->device->worm_command, "");
+      edit_device_codes(dcr, &wormcmd, dcr->device->worm_command, "");
       /* Wait maximum 5 minutes */
       bpipe = open_bpipe(wormcmd, 60 * 5, "r");
       if (bpipe) {