virshtest: refactor testCompareOutputLit

Use g_autofree and get rid of the cleanup label.

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 02:07:19 +01:00
parent 994688e0df
commit 8bacdde9d5

View File

@ -60,26 +60,20 @@ static int
testCompareOutputLit(const char *expectData, testCompareOutputLit(const char *expectData,
const char *filter, const char *const argv[]) const char *filter, const char *const argv[])
{ {
int result = -1; g_autofree char *actualData = NULL;
char *actualData = NULL;
if (virTestCaptureProgramOutput(argv, &actualData, 4096) < 0) if (virTestCaptureProgramOutput(argv, &actualData, 4096) < 0)
goto cleanup; return -1;
if (filter && testFilterLine(actualData, filter) < 0) if (filter && testFilterLine(actualData, filter) < 0)
goto cleanup; return -1;
if (STRNEQ(expectData, actualData)) { if (STRNEQ(expectData, actualData)) {
virTestDifference(stderr, expectData, actualData); virTestDifference(stderr, expectData, actualData);
goto cleanup; return -1;
} }
result = 0; return 0;
cleanup:
VIR_FREE(actualData);
return result;
} }
# define VIRSH_DEFAULT abs_top_builddir "/tools/virsh", \ # define VIRSH_DEFAULT abs_top_builddir "/tools/virsh", \