From dd0707be5f9153a78ea0a07ec72f4e1f341a38c9 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 17 Jan 2012 18:28:44 +0000 Subject: 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. --- df/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'df') 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); -- cgit