tools: virt-admin: do not leak daemon-log settings

The commands daemon-log-filters and daemon-log-outputs
are used both for getting and setting the variables.
But the getter receives an allocated string, which
we do not free.

Use separate variables for the getter and the setter
to get rid of the memory leak and to stop casting
away the const.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Ján Tomko 2020-08-02 23:35:16 +02:00
parent 9c4730c54b
commit e05487610c
1 changed files with 6 additions and 6 deletions

View File

@ -1037,17 +1037,17 @@ static const vshCmdOptDef opts_daemon_log_filters[] = {
static bool static bool
cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd) cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd)
{ {
char *filters = NULL;
vshAdmControlPtr priv = ctl->privData; vshAdmControlPtr priv = ctl->privData;
if (vshCommandOptBool(cmd, "filters")) { if (vshCommandOptBool(cmd, "filters")) {
if ((vshCommandOptStringReq(ctl, cmd, "filters", const char *filters = NULL;
(const char **) &filters) < 0 || if ((vshCommandOptStringReq(ctl, cmd, "filters", &filters) < 0 ||
virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) { virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) {
vshError(ctl, _("Unable to change daemon logging settings")); vshError(ctl, _("Unable to change daemon logging settings"));
return false; return false;
} }
} else { } else {
g_autofree char *filters = NULL;
if (virAdmConnectGetLoggingFilters(priv->conn, if (virAdmConnectGetLoggingFilters(priv->conn,
&filters, 0) < 0) { &filters, 0) < 0) {
vshError(ctl, _("Unable to get daemon logging filters information")); vshError(ctl, _("Unable to get daemon logging filters information"));
@ -1090,17 +1090,17 @@ static const vshCmdOptDef opts_daemon_log_outputs[] = {
static bool static bool
cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd) cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd)
{ {
char *outputs = NULL;
vshAdmControlPtr priv = ctl->privData; vshAdmControlPtr priv = ctl->privData;
if (vshCommandOptBool(cmd, "outputs")) { if (vshCommandOptBool(cmd, "outputs")) {
if ((vshCommandOptStringReq(ctl, cmd, "outputs", const char *outputs = NULL;
(const char **) &outputs) < 0 || if ((vshCommandOptStringReq(ctl, cmd, "outputs", &outputs) < 0 ||
virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) { virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) {
vshError(ctl, _("Unable to change daemon logging settings")); vshError(ctl, _("Unable to change daemon logging settings"));
return false; return false;
} }
} else { } else {
g_autofree char *outputs = NULL;
if (virAdmConnectGetLoggingOutputs(priv->conn, &outputs, 0) < 0) { if (virAdmConnectGetLoggingOutputs(priv->conn, &outputs, 0) < 0) {
vshError(ctl, _("Unable to get daemon logging outputs information")); vshError(ctl, _("Unable to get daemon logging outputs information"));
return false; return false;