testutils: use g_autofree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Ján Tomko 2020-02-09 01:47:22 +01:00
parent 879e9db194
commit 40656ff758

View File

@ -279,7 +279,7 @@ virTestLoadFileGetPath(const char *p,
char * char *
virTestLoadFilePath(const char *p, ...) virTestLoadFilePath(const char *p, ...)
{ {
char *path = NULL; g_autofree char *path = NULL;
char *ret = NULL; char *ret = NULL;
va_list ap; va_list ap;
@ -292,7 +292,6 @@ virTestLoadFilePath(const char *p, ...)
cleanup: cleanup:
va_end(ap); va_end(ap);
VIR_FREE(path);
return ret; return ret;
} }
@ -309,8 +308,8 @@ virJSONValuePtr
virTestLoadFileJSON(const char *p, ...) virTestLoadFileJSON(const char *p, ...)
{ {
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
char *jsonstr = NULL; g_autofree char *jsonstr = NULL;
char *path = NULL; g_autofree char *path = NULL;
va_list ap; va_list ap;
va_start(ap, p); va_start(ap, p);
@ -326,8 +325,6 @@ virTestLoadFileJSON(const char *p, ...)
cleanup: cleanup:
va_end(ap); va_end(ap);
VIR_FREE(jsonstr);
VIR_FREE(path);
return ret; return ret;
} }
@ -420,7 +417,7 @@ static int
virTestRewrapFile(const char *filename) virTestRewrapFile(const char *filename)
{ {
int ret = -1; int ret = -1;
char *script = NULL; g_autofree char *script = NULL;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
if (!(virStringHasSuffix(filename, ".args") || if (!(virStringHasSuffix(filename, ".args") ||
@ -435,7 +432,6 @@ virTestRewrapFile(const char *filename)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(script);
virCommandFree(cmd); virCommandFree(cmd);
return ret; return ret;
} }
@ -669,8 +665,8 @@ virTestCompareToFile(const char *actual,
const char *filename) const char *filename)
{ {
int ret = -1; int ret = -1;
char *filecontent = NULL; g_autofree char *filecontent = NULL;
char *fixedcontent = NULL; g_autofree char *fixedcontent = NULL;
const char *cmpcontent = actual; const char *cmpcontent = actual;
if (!cmpcontent) if (!cmpcontent)
@ -700,8 +696,6 @@ virTestCompareToFile(const char *actual,
ret = 0; ret = 0;
failure: failure:
VIR_FREE(fixedcontent);
VIR_FREE(filecontent);
return ret; return ret;
} }
@ -826,7 +820,7 @@ virTestSetEnvPath(void)
{ {
int ret = -1; int ret = -1;
const char *path = getenv("PATH"); const char *path = getenv("PATH");
char *new_path = NULL; g_autofree char *new_path = NULL;
if (path) { if (path) {
if (strstr(path, abs_builddir) != path) if (strstr(path, abs_builddir) != path)
@ -841,7 +835,6 @@ virTestSetEnvPath(void)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(new_path);
return ret; return ret;
} }
@ -1045,15 +1038,13 @@ virCapsPtr virTestGenericCapsInit(void)
if (virTestGetDebug() > 1) { if (virTestGetDebug() > 1) {
char *caps_str; g_autofree char *caps_str = NULL;
caps_str = virCapabilitiesFormatXML(caps); caps_str = virCapabilitiesFormatXML(caps);
if (!caps_str) if (!caps_str)
goto error; goto error;
VIR_TEST_DEBUG("Generic driver capabilities:\n%s", caps_str); VIR_TEST_DEBUG("Generic driver capabilities:\n%s", caps_str);
VIR_FREE(caps_str);
} }
return caps; return caps;
@ -1131,7 +1122,7 @@ testCompareDomXML2XMLFiles(virCapsPtr caps G_GNUC_UNUSED,
unsigned int parseFlags, unsigned int parseFlags,
testCompareDomXML2XMLResult expectResult) testCompareDomXML2XMLResult expectResult)
{ {
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
testCompareDomXML2XMLResult result; testCompareDomXML2XMLResult result;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -1184,7 +1175,6 @@ testCompareDomXML2XMLFiles(virCapsPtr caps G_GNUC_UNUSED,
expectResult, result); expectResult, result);
} }
VIR_FREE(actual);
virDomainDefFree(def); virDomainDefFree(def);
return ret; return ret;
} }