1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virLogDaemonPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-11 18:29:40 +01:00
parent bf666cac6b
commit c357518776

View File

@ -505,62 +505,54 @@ virLogDaemonPreExecRestart(const char *state_file,
virNetDaemonPtr dmn,
char **argv)
{
virJSONValuePtr child;
char *state = NULL;
virJSONValuePtr object = virJSONValueNewObject();
char *magic = NULL;
g_autoptr(virJSONValue) object = virJSONValueNewObject();
g_autoptr(virJSONValue) daemon = NULL;
g_autoptr(virJSONValue) handler = NULL;
g_autofree char *state = NULL;
g_autofree char *magic = NULL;
VIR_DEBUG("Running pre-restart exec");
if (!(child = virNetDaemonPreExecRestart(dmn)))
goto cleanup;
if (!(daemon = virNetDaemonPreExecRestart(dmn)))
return -1;
if (virJSONValueObjectAppend(object, "daemon", child) < 0) {
virJSONValueFree(child);
goto cleanup;
}
if (virJSONValueObjectAppend(object, "daemon", daemon) < 0)
return -1;
daemon = NULL;
if (!(magic = virLogDaemonGetExecRestartMagic()))
goto cleanup;
return -1;
if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
goto cleanup;
return -1;
if (!(child = virLogHandlerPreExecRestart(logDaemon->handler)))
goto cleanup;
if (virJSONValueObjectAppend(object, "handler", child) < 0) {
virJSONValueFree(child);
goto cleanup;
}
if (!(handler = virLogHandlerPreExecRestart(logDaemon->handler)))
return -1;
if (virJSONValueObjectAppend(object, "handler", handler) < 0)
return -1;
handler = NULL;
if (!(state = virJSONValueToString(object, true)))
goto cleanup;
return -1;
VIR_DEBUG("Saving state %s", state);
if (virFileWriteStr(state_file,
state, 0700) < 0) {
if (virFileWriteStr(state_file, state, 0700) < 0) {
virReportSystemError(errno,
_("Unable to save state file %s"),
state_file);
goto cleanup;
_("Unable to save state file %s"), state_file);
return -1;
}
if (execvp(argv[0], argv) < 0) {
virReportSystemError(errno, "%s",
_("Unable to restart self"));
goto cleanup;
return -1;
}
abort(); /* This should be impossible to reach */
cleanup:
VIR_FREE(magic);
VIR_FREE(state);
virJSONValueFree(object);
return -1;
return 0;
}