summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cat/virt-cat.c5
-rw-r--r--cat/virt-ls.c5
-rw-r--r--df/main.c5
-rw-r--r--edit/virt-edit.c5
-rw-r--r--fish/fish.c8
-rw-r--r--fish/options.c3
-rw-r--r--fish/options.h10
-rw-r--r--inspector/virt-inspector.c5
-rw-r--r--rescue/virt-rescue.c5
9 files changed, 23 insertions, 28 deletions
diff --git a/cat/virt-cat.c b/cat/virt-cat.c
index 4d37ddab..775c7735 100644
--- a/cat/virt-cat.c
+++ b/cat/virt-cat.c
@@ -189,18 +189,17 @@ main (int argc, char *argv[])
while (optind < argc - 1) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/cat/virt-ls.c b/cat/virt-ls.c
index b29af272..1ca016a8 100644
--- a/cat/virt-ls.c
+++ b/cat/virt-ls.c
@@ -297,18 +297,17 @@ main (int argc, char *argv[])
while (optind < argc - 1) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/df/main.c b/df/main.c
index 2429c322..d7fdf539 100644
--- a/df/main.c
+++ b/df/main.c
@@ -210,18 +210,17 @@ main (int argc, char *argv[])
while (optind < argc) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/edit/virt-edit.c b/edit/virt-edit.c
index 66866b7a..28cee566 100644
--- a/edit/virt-edit.c
+++ b/edit/virt-edit.c
@@ -227,18 +227,17 @@ main (int argc, char *argv[])
while (optind < argc - 1) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/fish/fish.c b/fish/fish.c
index b782b7cb..3cf15b20 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -341,13 +341,12 @@ main (int argc, char *argv[])
list_prepared_drives ();
exit (EXIT_SUCCESS);
}
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_N;
- drv->device = NULL;
drv->nr_drives = -1;
if (asprintf (&drv->N.filename, "test%d.img",
next_prepared_drive++) == -1) {
@@ -415,18 +414,17 @@ main (int argc, char *argv[])
while (optind < argc) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/fish/options.c b/fish/options.c
index 48c8e1c2..f6523898 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -43,6 +43,9 @@ add_drives (struct drv *drv, char next_drive)
if (drv) {
next_drive = add_drives (drv->next, next_drive);
+ free (drv->device);
+ drv->device = NULL;
+
if (asprintf (&drv->device, "/dev/sd%c", next_drive) == -1) {
perror ("asprintf");
exit (EXIT_FAILURE);
diff --git a/fish/options.h b/fish/options.h
index 9b9aee5e..7411a2ab 100644
--- a/fish/options.h
+++ b/fish/options.h
@@ -75,7 +75,9 @@ extern int echo_keys;
extern const char *libvirt_uri;
extern const char *program_name;
-/* List of drives added via -a, -d or -N options. */
+/* List of drives added via -a, -d or -N options. NB: Unused fields
+ * in this struct MUST be zeroed, ie. use calloc, not malloc.
+ */
struct drv {
struct drv *next;
@@ -139,13 +141,12 @@ extern int add_libvirt_drives (const char *guest);
perror (optarg); \
exit (EXIT_FAILURE); \
} \
- drv = malloc (sizeof (struct drv)); \
+ drv = calloc (1, sizeof (struct drv)); \
if (!drv) { \
perror ("malloc"); \
exit (EXIT_FAILURE); \
} \
drv->type = drv_a; \
- drv->device = NULL; \
drv->nr_drives = -1; \
drv->a.filename = optarg; \
drv->a.format = format; \
@@ -156,13 +157,12 @@ extern int add_libvirt_drives (const char *guest);
libvirt_uri = optarg
#define OPTION_d \
- drv = malloc (sizeof (struct drv)); \
+ drv = calloc (1, sizeof (struct drv)); \
if (!drv) { \
perror ("malloc"); \
exit (EXIT_FAILURE); \
} \
drv->type = drv_d; \
- drv->device = NULL; \
drv->nr_drives = -1; \
drv->d.guest = optarg; \
drv->next = drvs; \
diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c
index 09621abb..6b7cbe62 100644
--- a/inspector/virt-inspector.c
+++ b/inspector/virt-inspector.c
@@ -209,18 +209,17 @@ main (int argc, char *argv[])
while (optind < argc) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
diff --git a/rescue/virt-rescue.c b/rescue/virt-rescue.c
index 9a354b82..efde9837 100644
--- a/rescue/virt-rescue.c
+++ b/rescue/virt-rescue.c
@@ -240,18 +240,17 @@ main (int argc, char *argv[])
while (optind < argc) {
if (strchr (argv[optind], '/') ||
access (argv[optind], F_OK) == 0) { /* simulate -a option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
drv->a.filename = argv[optind];
- drv->a.format = NULL;
drv->next = drvs;
drvs = drv;
} else { /* simulate -d option */
- drv = malloc (sizeof (struct drv));
+ drv = calloc (1, sizeof (struct drv));
if (!drv) {
perror ("malloc");
exit (EXIT_FAILURE);