static char add_drives (struct drv *drv, char next_drive);
static void prepare_drives (struct drv *drv);
static void mount_mps (struct mp *mp);
+static void free_drives (struct drv *drv);
+static void free_mps (struct mp *mp);
static int launch (void);
static void interactive (void);
static void shell_script (void);
mount_mps (mps);
}
+ /* Free up data structures, no longer needed after this point. */
+ free_drives (drvs);
+ free_mps (mps);
+
/* Remote control? */
if (remote_control_listen && remote_control) {
fprintf (stderr,
}
}
+static void
+free_drives (struct drv *drv)
+{
+ if (!drv) return;
+ free_drives (drv->next);
+
+ switch (drv->type) {
+ case drv_a: free (drv->a.filename); break;
+ case drv_d: free (drv->d.guest); break;
+ case drv_N:
+ free (drv->N.filename);
+ free (drv->N.device);
+ free_prep_data (drv->N.data);
+ break;
+ default: ; /* keep GCC happy */
+ }
+ free (drv);
+}
+
+static void
+free_mps (struct mp *mp)
+{
+ if (!mp) return;
+ free_mps (mp->next);
+
+ /* The drive and mountpoint fields are not allocated
+ * from the heap, so we should not free them here.
+ */
+
+ free (mp);
+}
+
static int
launch (void)
{
struct prep_data {
const struct prep *prep;
const char *orig_type_string;
- const char **params;
+ char **params;
};
typedef struct prep_data prep_data;
extern void list_prepared_drives (void);
extern void prepare_drive (const char *filename, prep_data *data,
const char *device);
extern void prep_error (prep_data *data, const char *filename, const char *fs, ...) __attribute__((noreturn, format (printf,3,4)));
+extern void free_prep_data (prep_data *data);
/* in prep_lv.c */
extern int vg_lv_parse (const char *device, char **vg, char **lv);
}
for (i = 0; i < data->prep->nr_params; ++i)
- data->params[i] = data->prep->params[i].pdefault;
+ data->params[i] = bad_cast (data->prep->params[i].pdefault);
/* Parse the optional parameters. */
const char *p = type_string + len;
exit (EXIT_FAILURE);
}
+
+void
+free_prep_data (prep_data *data)
+{
+ size_t i;
+
+ for (i = 0; i < data->prep->nr_params; ++i)
+ if (data->params[i] != data->prep->params[i].pdefault)
+ free (data->params[i]);
+ free (data->params);
+ free (data);
+}