mirror of https://gitee.com/openkylin/libvirt.git
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:
parent
9c4730c54b
commit
e05487610c
|
@ -1037,17 +1037,17 @@ static const vshCmdOptDef opts_daemon_log_filters[] = {
|
|||
static bool
|
||||
cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
char *filters = NULL;
|
||||
vshAdmControlPtr priv = ctl->privData;
|
||||
|
||||
if (vshCommandOptBool(cmd, "filters")) {
|
||||
if ((vshCommandOptStringReq(ctl, cmd, "filters",
|
||||
(const char **) &filters) < 0 ||
|
||||
const char *filters = NULL;
|
||||
if ((vshCommandOptStringReq(ctl, cmd, "filters", &filters) < 0 ||
|
||||
virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) {
|
||||
vshError(ctl, _("Unable to change daemon logging settings"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
g_autofree char *filters = NULL;
|
||||
if (virAdmConnectGetLoggingFilters(priv->conn,
|
||||
&filters, 0) < 0) {
|
||||
vshError(ctl, _("Unable to get daemon logging filters information"));
|
||||
|
@ -1090,17 +1090,17 @@ static const vshCmdOptDef opts_daemon_log_outputs[] = {
|
|||
static bool
|
||||
cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
char *outputs = NULL;
|
||||
vshAdmControlPtr priv = ctl->privData;
|
||||
|
||||
if (vshCommandOptBool(cmd, "outputs")) {
|
||||
if ((vshCommandOptStringReq(ctl, cmd, "outputs",
|
||||
(const char **) &outputs) < 0 ||
|
||||
const char *outputs = NULL;
|
||||
if ((vshCommandOptStringReq(ctl, cmd, "outputs", &outputs) < 0 ||
|
||||
virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) {
|
||||
vshError(ctl, _("Unable to change daemon logging settings"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
g_autofree char *outputs = NULL;
|
||||
if (virAdmConnectGetLoggingOutputs(priv->conn, &outputs, 0) < 0) {
|
||||
vshError(ctl, _("Unable to get daemon logging outputs information"));
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue