qemumonitorjsontest: Resolve resource leaks found by Valgrind

The 'package' string returned by qemuMonitorGetVersion() needs to
be VIR_FREE()'d.

testQemuMonitorJSONGetMachines(), testQemuMonitorJSONGetCPUDefinitions(),
and testQemuMonitorJSONGetCommands() did not VIR_FREE() the array and
array elements allocated by their respective qemuMonitorGet* routines.
This commit is contained in:
John Ferlan 2013-02-04 11:17:52 -05:00
parent 890b6b351f
commit 3f5250ff8e

View File

@ -131,7 +131,7 @@ testQemuMonitorJSONGetVersion(const void *data)
int major; int major;
int minor; int minor;
int micro; int micro;
char *package; char *package = NULL;
if (!test) if (!test)
return -1; return -1;
@ -188,6 +188,7 @@ testQemuMonitorJSONGetVersion(const void *data)
"Package %s was not ''", package); "Package %s was not ''", package);
goto cleanup; goto cleanup;
} }
VIR_FREE(package);
if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test), if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test),
&major, &minor, &micro, &major, &minor, &micro,
@ -220,6 +221,7 @@ testQemuMonitorJSONGetVersion(const void *data)
cleanup: cleanup:
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
VIR_FREE(package);
return ret; return ret;
} }
@ -230,8 +232,9 @@ testQemuMonitorJSONGetMachines(const void *data)
qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps);
int ret = -1; int ret = -1;
qemuMonitorMachineInfoPtr *info; qemuMonitorMachineInfoPtr *info;
int ninfo; int ninfo = 0;
const char *null = NULL; const char *null = NULL;
int i;
if (!test) if (!test)
return -1; return -1;
@ -296,6 +299,10 @@ testQemuMonitorJSONGetMachines(const void *data)
cleanup: cleanup:
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
for (i = 0; i < ninfo; i++)
qemuMonitorMachineInfoFree(info[i]);
VIR_FREE(info);
return ret; return ret;
} }
@ -307,7 +314,8 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps);
int ret = -1; int ret = -1;
char **cpus = NULL; char **cpus = NULL;
int ncpus; int ncpus = 0;
int i;
if (!test) if (!test)
return -1; return -1;
@ -358,6 +366,9 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
cleanup: cleanup:
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
for (i = 0; i < ncpus; i++)
VIR_FREE(cpus[i]);
VIR_FREE(cpus);
return ret; return ret;
} }
@ -369,7 +380,8 @@ testQemuMonitorJSONGetCommands(const void *data)
qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps);
int ret = -1; int ret = -1;
char **commands = NULL; char **commands = NULL;
int ncommands; int ncommands = 0;
int i;
if (!test) if (!test)
return -1; return -1;
@ -419,6 +431,9 @@ testQemuMonitorJSONGetCommands(const void *data)
cleanup: cleanup:
qemuMonitorTestFree(test); qemuMonitorTestFree(test);
for (i = 0; i < ncommands; i++)
VIR_FREE(commands[i]);
VIR_FREE(commands);
return ret; return ret;
} }