From: norbert.bizet Date: Wed, 12 Oct 2022 15:46:10 +0000 (-0400) Subject: Change edit_device_codes() prototype to avoid POOLMEM leaks X-Git-Tag: Beta-15.0.0~483 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75db43da883cdb76674ecc4718c112acf357421f;p=thirdparty%2Fbacula.git Change edit_device_codes() prototype to avoid POOLMEM leaks --- diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 71256b792..c1002e1f4 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -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; } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index fd172182f..f31f1cc5f 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -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); diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 21293224a..1ebc8c330 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -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 */ diff --git a/bacula/src/stored/sd_plugins.c b/bacula/src/stored/sd_plugins.c index c42231845..f5efd47a9 100644 --- a/bacula/src/stored/sd_plugins.c +++ b/bacula/src/stored/sd_plugins.c @@ -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 diff --git a/bacula/src/stored/sd_plugins.h b/bacula/src/stored/sd_plugins.h index e377840d9..3db864504 100644 --- a/bacula/src/stored/sd_plugins.h +++ b/bacula/src/stored/sd_plugins.h @@ -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; diff --git a/bacula/src/stored/tape_alert.c b/bacula/src/stored/tape_alert.c index f5c24988a..5cadb482f 100644 --- a/bacula/src/stored/tape_alert.c +++ b/bacula/src/stored/tape_alert.c @@ -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) { diff --git a/bacula/src/stored/tape_worm.c b/bacula/src/stored/tape_worm.c index e4ef6c864..f20792b2f 100644 --- a/bacula/src/stored/tape_worm.c +++ b/bacula/src/stored/tape_worm.c @@ -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) {