summaryrefslogtreecommitdiffstats
path: root/cat
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-01-17 18:28:44 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-01-18 16:28:10 +0000
commitdd0707be5f9153a78ea0a07ec72f4e1f341a38c9 (patch)
treeee6806b89a42383a4da35310830bb71fc344b826 /cat
parentfd1a6d8003b29eaec5230f838f673df7cd0e9c86 (diff)
downloadlibguestfs-dd0707be5f9153a78ea0a07ec72f4e1f341a38c9.tar.gz
libguestfs-dd0707be5f9153a78ea0a07ec72f4e1f341a38c9.tar.xz
libguestfs-dd0707be5f9153a78ea0a07ec72f4e1f341a38c9.zip
fish options parsing: Allow add_drives to be called multiple times.
Ensure that the drv structure is always zeroed on allocation. Don't leak old drv->device when add_drives is called multiple times.
Diffstat (limited to 'cat')
-rw-r--r--cat/virt-cat.c5
-rw-r--r--cat/virt-ls.c5
2 files changed, 4 insertions, 6 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);