aboutsummaryrefslogtreecommitdiff
path: root/tests/hd-geo-test.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-02-05 14:11:56 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2017-03-01 11:51:04 +0400
commit2c8f86961b6eaac705be21bc98299f5517eb0b6b (patch)
tree0ce969d2eba1fb2e70c6e44dec9d6f8f4dffd19f /tests/hd-geo-test.c
parentf5aa4bdc766190b95d18be27d5cdf4d80c35b33c (diff)
downloadqemu-2c8f86961b6eaac705be21bc98299f5517eb0b6b.zip
qemu-2c8f86961b6eaac705be21bc98299f5517eb0b6b.tar.gz
qemu-2c8f86961b6eaac705be21bc98299f5517eb0b6b.tar.bz2
tests: fix hd-geo-test leaks
Spotted by ASAN. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/hd-geo-test.c')
-rw-r--r--tests/hd-geo-test.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c
index 6176e81..24870b3 100644
--- a/tests/hd-geo-test.c
+++ b/tests/hd-geo-test.c
@@ -19,6 +19,8 @@
#include "qemu-common.h"
#include "libqtest.h"
+#define ARGV_SIZE 256
+
static char *create_test_img(int secs)
{
char *template = strdup("/tmp/qtest.XXXXXX");
@@ -66,7 +68,7 @@ static const CHST hd_chst[backend_last][mbr_last] = {
},
};
-static const char *img_file_name[backend_last];
+static char *img_file_name[backend_last];
static const CHST *cur_ide[4];
@@ -234,28 +236,36 @@ static int setup_ide(int argc, char *argv[], int argv_sz,
*/
static void test_ide_none(void)
{
- char *argv[256];
-
- setup_common(argv, ARRAY_SIZE(argv));
- qtest_start(g_strjoinv(" ", argv));
+ char **argv = g_new0(char *, ARGV_SIZE);
+ char *args;
+
+ setup_common(argv, ARGV_SIZE);
+ args = g_strjoinv(" ", argv);
+ qtest_start(args);
+ g_strfreev(argv);
+ g_free(args);
test_cmos();
qtest_end();
}
static void test_ide_mbr(bool use_device, MBRcontents mbr)
{
- char *argv[256];
+ char **argv = g_new0(char *, ARGV_SIZE);
+ char *args;
int argc;
Backend i;
const char *dev;
- argc = setup_common(argv, ARRAY_SIZE(argv));
+ argc = setup_common(argv, ARGV_SIZE);
for (i = 0; i < backend_last; i++) {
cur_ide[i] = &hd_chst[i][mbr];
dev = use_device ? (is_hd(cur_ide[i]) ? "ide-hd" : "ide-cd") : NULL;
- argc = setup_ide(argc, argv, ARRAY_SIZE(argv), i, dev, i, mbr, "");
+ argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr, "");
}
- qtest_start(g_strjoinv(" ", argv));
+ args = g_strjoinv(" ", argv);
+ qtest_start(args);
+ g_strfreev(argv);
+ g_free(args);
test_cmos();
qtest_end();
}
@@ -310,12 +320,13 @@ static void test_ide_device_mbr_chs(void)
static void test_ide_drive_user(const char *dev, bool trans)
{
- char *argv[256], *opts;
+ char **argv = g_new0(char *, ARGV_SIZE);
+ char *args, *opts;
int argc;
int secs = img_secs[backend_small];
const CHST expected_chst = { secs / (4 * 32) , 4, 32, trans };
- argc = setup_common(argv, ARRAY_SIZE(argv));
+ argc = setup_common(argv, ARGV_SIZE);
opts = g_strdup_printf("%s,%s%scyls=%d,heads=%d,secs=%d",
dev ?: "",
trans && dev ? "bios-chs-" : "",
@@ -323,11 +334,14 @@ static void test_ide_drive_user(const char *dev, bool trans)
expected_chst.cyls, expected_chst.heads,
expected_chst.secs);
cur_ide[0] = &expected_chst;
- argc = setup_ide(argc, argv, ARRAY_SIZE(argv),
+ argc = setup_ide(argc, argv, ARGV_SIZE,
0, dev ? opts : NULL, backend_small, mbr_chs,
dev ? "" : opts);
g_free(opts);
- qtest_start(g_strjoinv(" ", argv));
+ args = g_strjoinv(" ", argv);
+ qtest_start(args);
+ g_strfreev(argv);
+ g_free(args);
test_cmos();
qtest_end();
}
@@ -369,18 +383,22 @@ static void test_ide_device_user_chst(void)
*/
static void test_ide_drive_cd_0(void)
{
- char *argv[256];
+ char **argv = g_new0(char *, ARGV_SIZE);
+ char *args;
int argc, ide_idx;
Backend i;
- argc = setup_common(argv, ARRAY_SIZE(argv));
+ argc = setup_common(argv, ARGV_SIZE);
for (i = 0; i <= backend_empty; i++) {
ide_idx = backend_empty - i;
cur_ide[ide_idx] = &hd_chst[i][mbr_blank];
- argc = setup_ide(argc, argv, ARRAY_SIZE(argv),
+ argc = setup_ide(argc, argv, ARGV_SIZE,
ide_idx, NULL, i, mbr_blank, "");
}
- qtest_start(g_strjoinv(" ", argv));
+ args = g_strjoinv(" ", argv);
+ qtest_start(args);
+ g_strfreev(argv);
+ g_free(args);
test_cmos();
qtest_end();
}
@@ -418,6 +436,7 @@ int main(int argc, char **argv)
for (i = 0; i < backend_last; i++) {
if (img_file_name[i]) {
unlink(img_file_name[i]);
+ free(img_file_name[i]);
}
}