diff --git a/fish/copy.c b/fish/copy.c index 50f741042..ecbd2da25 100644 --- a/fish/copy.c +++ b/fish/copy.c @@ -44,31 +44,29 @@ static int split_path (char *buf, size_t buf_size, const char *path, const char int run_copy_in (const char *cmd, size_t argc, char *argv[]) { + CLEANUP_FREE char *remote = NULL; + if (argc < 2) { fprintf (stderr, _("use 'copy-in [...] ' to copy files into the image\n")); return -1; } - /* Remote directory is always the last arg. */ - char *remote = argv[argc-1]; - - /* Allow win: prefix on remote. */ - remote = win_prefix (remote); + /* Remote directory is always the last arg. + * Allow "win:" prefix on remote. + */ + remote = win_prefix (argv[argc-1]); if (remote == NULL) return -1; int nr_locals = argc-1; int remote_is_dir = guestfs_is_dir (g, remote); - if (remote_is_dir == -1) { - free (remote); + if (remote_is_dir == -1) return -1; - } if (!remote_is_dir) { fprintf (stderr, _("copy-in: target '%s' is not a directory\n"), remote); - free (remote); return -1; } @@ -76,10 +74,8 @@ run_copy_in (const char *cmd, size_t argc, char *argv[]) int i; for (i = 0; i < nr_locals; ++i) { struct fd_pid fdpid = make_tar_from_local (argv[i]); - if (fdpid.fd == -1) { - free (remote); + if (fdpid.fd == -1) return -1; - } char fdbuf[64]; snprintf (fdbuf, sizeof fdbuf, "/dev/fd/%d", fdpid.fd); @@ -94,22 +90,15 @@ run_copy_in (const char *cmd, size_t argc, char *argv[]) int status; if (waitpid (fdpid.pid, &status, 0) == -1) { perror ("wait (tar-from-local subprocess)"); - free (remote); return -1; } - if (!(WIFEXITED (status) && WEXITSTATUS (status) == 0)) { - free (remote); + if (!(WIFEXITED (status) && WEXITSTATUS (status) == 0)) return -1; - } - if (r == -1) { - free (remote); + if (r == -1) return -1; - } } - free (remote); - return 0; } @@ -228,10 +217,10 @@ run_copy_out (const char *cmd, size_t argc, char *argv[]) /* Download each remote one at a time using tar-out. */ int i, r; for (i = 0; i < nr_remotes; ++i) { - char *remote = argv[i]; + CLEANUP_FREE char *remote; /* Allow win:... prefix on remotes. */ - remote = win_prefix (remote); + remote = win_prefix (argv[i]); if (remote == NULL) return -1; @@ -239,53 +228,40 @@ run_copy_out (const char *cmd, size_t argc, char *argv[]) * create the directory in local first before using tar-out. */ r = guestfs_is_file (g, remote); - if (r == -1) { - free (remote); + if (r == -1) return -1; - } if (r == 1) { /* is file */ + CLEANUP_FREE char *filename = NULL; size_t buf_len = strlen (remote) + 1; char buf[buf_len]; const char *basename; - if (split_path (buf, buf_len, remote, NULL, &basename) == -1) { - free (remote); - return -1; - } - char *filename; + if (split_path (buf, buf_len, remote, NULL, &basename) == -1) + return -1; + if (asprintf (&filename, "%s/%s", local, basename) == -1) { perror ("asprintf"); - free (remote); return -1; } - if (guestfs_download (g, remote, filename) == -1) { - free (remote); - free (filename); + if (guestfs_download (g, remote, filename) == -1) return -1; - } - free (filename); } else { /* not a regular file */ r = guestfs_is_dir (g, remote); - if (r == -1) { - free (remote); + if (r == -1) return -1; - } if (r == 0) { fprintf (stderr, _("copy-out: '%s' is not a file or directory\n"), remote); - free (remote); return -1; } size_t buf_len = strlen (remote) + 1; char buf[buf_len]; const char *basename; - if (split_path (buf, buf_len, remote, NULL, &basename) == -1) { - free (remote); + if (split_path (buf, buf_len, remote, NULL, &basename) == -1) return -1; - } /* RHBZ#845522: If remote == "/" then basename would be an empty * string. Replace it with "." so that make_tar_output writes @@ -295,10 +271,8 @@ run_copy_out (const char *cmd, size_t argc, char *argv[]) basename = "."; struct fd_pid fdpid = make_tar_output (local, basename); - if (fdpid.fd == -1) { - free (remote); + if (fdpid.fd == -1) return -1; - } char fdbuf[64]; snprintf (fdbuf, sizeof fdbuf, "/dev/fd/%d", fdpid.fd); @@ -307,28 +281,20 @@ run_copy_out (const char *cmd, size_t argc, char *argv[]) if (close (fdpid.fd) == -1) { perror ("close (tar-output subprocess)"); - free (remote); r = -1; } int status; if (waitpid (fdpid.pid, &status, 0) == -1) { perror ("wait (tar-output subprocess)"); - free (remote); return -1; } - if (!(WIFEXITED (status) && WEXITSTATUS (status) == 0)) { - free (remote); + if (!(WIFEXITED (status) && WEXITSTATUS (status) == 0)) return -1; - } - if (r == -1) { - free (remote); + if (r == -1) return -1; - } } - - free (remote); } return 0; diff --git a/fish/display.c b/fish/display.c index 4fa812374..c5655468d 100644 --- a/fish/display.c +++ b/fish/display.c @@ -34,7 +34,7 @@ int run_display (const char *cmd, size_t argc, char *argv[]) { CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g), *filename = NULL; - char *remote; + CLEANUP_FREE char *remote = NULL; const char *display; char buf[256]; int r, fd; @@ -49,24 +49,20 @@ run_display (const char *cmd, size_t argc, char *argv[]) if (display == NULL) display = "display"; - remote = argv[0]; - /* Allow win:... prefix on remote. */ - remote = win_prefix (remote); + remote = win_prefix (argv[0]); if (remote == NULL) return -1; /* Download the file and write it to a temporary. */ if (asprintf (&filename, "%s/guestfishXXXXXX", tmpdir) == -1) { perror ("asprintf"); - free (remote); return -1; } fd = mkstemp (filename); if (fd == -1) { perror ("mkstemp"); - free (remote); return -1; } @@ -75,14 +71,12 @@ run_display (const char *cmd, size_t argc, char *argv[]) if (guestfs_download (g, remote, buf) == -1) { close (fd); unlink (filename); - free (remote); return -1; } if (close (fd) == -1) { perror (filename); unlink (filename); - free (remote); return -1; } @@ -93,10 +87,8 @@ run_display (const char *cmd, size_t argc, char *argv[]) unlink (filename); if (r != 0) { perror (buf); - free (remote); return -1; } - free (remote); return 0; } diff --git a/fish/edit.c b/fish/edit.c index 217ec1e12..d710a3b88 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -39,16 +39,17 @@ static int copy_attributes (const char *src, const char *dest); int run_edit (const char *cmd, size_t argc, char *argv[]) { - CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g), *filename = NULL; + CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g); + CLEANUP_UNLINK_FREE char *filename = NULL; char buf[256]; const char *editor; - char *remotefilename, *newname; + CLEANUP_FREE char *remotefilename = NULL, *newname = NULL; struct stat oldstat, newstat; int r, fd; if (argc != 1) { fprintf (stderr, _("use '%s filename' to edit a file\n"), cmd); - goto error0; + return -1; } /* Choose an editor. */ @@ -65,36 +66,36 @@ run_edit (const char *cmd, size_t argc, char *argv[]) /* Handle 'win:...' prefix. */ remotefilename = win_prefix (argv[0]); if (remotefilename == NULL) - goto error0; + return -1; /* Download the file and write it to a temporary. */ if (asprintf (&filename, "%s/guestfishXXXXXX", tmpdir) == -1) { perror ("asprintf"); - goto error1; + return -1; } fd = mkstemp (filename); if (fd == -1) { perror ("mkstemp"); - goto error1; + return -1; } snprintf (buf, sizeof buf, "/dev/fd/%d", fd); if (guestfs_download (g, remotefilename, buf) == -1) { close (fd); - goto error2; + return -1; } if (close (fd) == -1) { perror (filename); - goto error2; + return -1; } /* Get the old stat. */ if (stat (filename, &oldstat) == -1) { perror (filename); - goto error2; + return -1; } /* Edit it. */ @@ -104,22 +105,19 @@ run_edit (const char *cmd, size_t argc, char *argv[]) r = system (buf); if (r != 0) { perror (buf); - goto error2; + return -1; } /* Get the new stat. */ if (stat (filename, &newstat) == -1) { perror (filename); - goto error2; + return -1; } /* Changed? */ if (oldstat.st_ctime == newstat.st_ctime && - oldstat.st_size == newstat.st_size) { - unlink (filename); - free (remotefilename); + oldstat.st_size == newstat.st_size) return 0; - } /* Upload to a new file in the same directory, so if it fails we * don't end up with a partially written file. Give the new file @@ -128,34 +126,22 @@ run_edit (const char *cmd, size_t argc, char *argv[]) */ newname = generate_random_name (remotefilename); if (!newname) - goto error2; + return -1; /* Write new content. */ if (guestfs_upload (g, filename, newname) == -1) - goto error3; + return -1; /* Set the permissions, UID, GID and SELinux context of the new * file to match the old file (RHBZ#788641). */ if (copy_attributes (remotefilename, newname) == -1) - goto error3; + return -1; if (guestfs_mv (g, newname, remotefilename) == -1) - goto error3; + return -1; - free (newname); - unlink (filename); - free (remotefilename); return 0; - - error3: - free (newname); - error2: - unlink (filename); - error1: - free (remotefilename); - error0: - return -1; } static char @@ -197,7 +183,7 @@ copy_attributes (const char *src, const char *dest) { struct guestfs_stat *stat; int has_linuxxattrs; - char *selinux_context = NULL; + CLEANUP_FREE char *selinux_context = NULL; size_t selinux_context_size; has_linuxxattrs = feature_available (g, "linuxxattrs"); @@ -234,12 +220,9 @@ copy_attributes (const char *src, const char *dest) /* Set the SELinux context. */ if (has_linuxxattrs && selinux_context) { if (guestfs_setxattr (g, "security.selinux", selinux_context, - (int) selinux_context_size, dest) == -1) { - free (selinux_context); + (int) selinux_context_size, dest) == -1) return -1; - } } - free (selinux_context); return 0; } diff --git a/fish/fish.c b/fish/fish.c index 9a04a07f4..9e4a4eab1 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -624,7 +624,7 @@ static char * rl_gets (int prompt) { #ifdef HAVE_LIBREADLINE - char *p = NULL; + CLEANUP_FREE char *p = NULL; if (prompt) { if (line_read) { @@ -634,7 +634,6 @@ rl_gets (int prompt) p = prompt && ps1 ? decode_ps1 (ps1) : NULL; line_read = readline (prompt ? (ps1 ? p : FISH) : ""); - free (p); if (line_read && *line_read) add_history_line (line_read); @@ -972,7 +971,7 @@ static int execute_and_inline (const char *cmd, int global_exit_on_error) { FILE *pp; - char *line = NULL; + CLEANUP_FREE char *line = NULL; size_t len = 0; ssize_t n; int exit_on_error; @@ -1001,8 +1000,6 @@ execute_and_inline (const char *cmd, int global_exit_on_error) } } - free (line); - if (pclose (pp) != 0) { perror ("pclose"); return -1; @@ -1695,26 +1692,26 @@ win_prefix (const char *path) static char * win_prefix_drive_letter (char drive_letter, const char *path) { - char **roots = NULL; - char **drives = NULL; - char **mountpoints = NULL; + CLEANUP_FREE_STRING_LIST char **roots = NULL; + CLEANUP_FREE_STRING_LIST char **drives = NULL; + CLEANUP_FREE_STRING_LIST char **mountpoints = NULL; char *device, *mountpoint, *ret = NULL; size_t i; /* Resolve the drive letter using the drive mappings table. */ roots = guestfs_inspect_get_roots (g); if (roots == NULL) - goto out; + return NULL; if (roots[0] == NULL) { fprintf (stderr, _("%s: to use Windows drive letters, you must inspect the guest (\"-i\" option or run \"inspect-os\" command)\n"), program_name); - goto out; + return NULL; } drives = guestfs_inspect_get_drive_mappings (g, roots[0]); if (drives == NULL || drives[0] == NULL) { fprintf (stderr, _("%s: to use Windows drive letters, this must be a Windows guest\n"), program_name); - goto out; + return NULL; } device = NULL; @@ -1728,13 +1725,13 @@ win_prefix_drive_letter (char drive_letter, const char *path) if (device == NULL) { fprintf (stderr, _("%s: drive '%c:' not found. To list available drives do:\n inspect-get-drive-mappings %s\n"), program_name, drive_letter, roots[0]); - goto out; + return NULL; } /* This drive letter must be mounted somewhere (we won't do it). */ mountpoints = guestfs_mountpoints (g); if (mountpoints == NULL) - goto out; + return NULL; mountpoint = NULL; for (i = 0; mountpoints[i] != NULL; i += 2) { @@ -1747,24 +1744,16 @@ win_prefix_drive_letter (char drive_letter, const char *path) if (mountpoint == NULL) { fprintf (stderr, _("%s: to access '%c:', mount %s first. One way to do this is:\n umount-all\n mount %s /\n"), program_name, drive_letter, device, device); - goto out; + return NULL; } /* Rewrite the path, eg. if C: => /c then C:/foo => /c/foo */ if (asprintf (&ret, "%s%s%s", mountpoint, STRNEQ (mountpoint, "/") ? "/" : "", path) == -1) { perror ("asprintf"); - goto out; + return NULL; } - out: - if (roots) - free_strings (roots); - if (drives) - free_strings (drives); - if (mountpoints) - free_strings (mountpoints); - return ret; } diff --git a/fish/inspect.c b/fish/inspect.c index 552c21997..9422d4020 100644 --- a/fish/inspect.c +++ b/fish/inspect.c @@ -137,7 +137,8 @@ inspect_mount (void) void inspect_mount_root (const char *root) { - char **mountpoints = guestfs_inspect_get_mountpoints (g, root); + CLEANUP_FREE_STRING_LIST char **mountpoints = + guestfs_inspect_get_mountpoints (g, root); if (mountpoints == NULL) exit (EXIT_FAILURE); @@ -165,8 +166,6 @@ inspect_mount_root (const char *root) } } - free_strings (mountpoints); - if (mount_errors) fprintf (stderr, _("%s: some filesystems could not be mounted (ignored)\n"), program_name); @@ -179,13 +178,12 @@ void print_inspect_prompt (void) { size_t i; - char *name, *dev; - char **mountpoints; + CLEANUP_FREE char *name = NULL; + CLEANUP_FREE_STRING_LIST char **mountpoints; name = guestfs_inspect_get_product_name (g, root); if (name && STRNEQ (name, "unknown")) printf (_("Operating system: %s\n"), name); - free (name); mountpoints = guestfs_inspect_get_mountpoints (g, root); if (mountpoints == NULL) @@ -199,14 +197,12 @@ print_inspect_prompt (void) /* Try to make the device name canonical for printing, but don't * worry if this fails. */ - dev = guestfs_canonical_device_name (g, mountpoints[i+1]); - if (!dev) - dev = mountpoints[i+1]; + CLEANUP_FREE char *dev = + guestfs_canonical_device_name (g, mountpoints[i+1]); - printf (_("%s mounted on %s\n"), dev, mountpoints[i]); + printf (_("%s mounted on %s\n"), + dev ? dev : mountpoints[i+1], mountpoints[i]); } - - free_strings (mountpoints); } /* Make a LUKS map name from the partition name, @@ -244,34 +240,29 @@ make_mapname (const char *device, char *mapname, size_t len) void inspect_do_decrypt (void) { - char **partitions = guestfs_list_partitions (g); + CLEANUP_FREE_STRING_LIST char **partitions = guestfs_list_partitions (g); if (partitions == NULL) exit (EXIT_FAILURE); int need_rescan = 0; size_t i; for (i = 0; partitions[i] != NULL; ++i) { - char *type = guestfs_vfs_type (g, partitions[i]); + CLEANUP_FREE char *type = guestfs_vfs_type (g, partitions[i]); if (type && STREQ (type, "crypto_LUKS")) { char mapname[32]; make_mapname (partitions[i], mapname, sizeof mapname); - char *key = read_key (partitions[i]); + CLEANUP_FREE char *key = read_key (partitions[i]); /* XXX Should we call guestfs_luks_open_ro if readonly flag * is set? This might break 'mount_ro'. */ if (guestfs_luks_open (g, partitions[i], key, mapname) == -1) exit (EXIT_FAILURE); - free (key); - need_rescan = 1; } - free (type); } - free_strings (partitions); - if (need_rescan) { if (guestfs_vgscan (g) == -1) exit (EXIT_FAILURE); diff --git a/fish/more.c b/fish/more.c index bfcc44ae4..7b37b9910 100644 --- a/fish/more.c +++ b/fish/more.c @@ -31,9 +31,10 @@ int run_more (const char *cmd, size_t argc, char *argv[]) { - CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g), *filename = NULL; + CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g); + CLEANUP_UNLINK_FREE char *filename = NULL; char buf[256]; - char *remote; + CLEANUP_FREE char *remote = NULL; const char *pager; int r, fd; @@ -51,24 +52,20 @@ run_more (const char *cmd, size_t argc, char *argv[]) pager = "more"; } - remote = argv[0]; - /* Allow win:... prefix on remote. */ - remote = win_prefix (remote); + remote = win_prefix (argv[0]); if (remote == NULL) return -1; /* Download the file and write it to a temporary. */ if (asprintf (&filename, "%s/guestfishXXXXXX", tmpdir) == -1) { perror ("asprintf"); - free (remote); return -1; } fd = mkstemp (filename); if (fd == -1) { perror ("mkstemp"); - free (remote); return -1; } @@ -76,15 +73,11 @@ run_more (const char *cmd, size_t argc, char *argv[]) if (guestfs_download (g, remote, buf) == -1) { close (fd); - unlink (filename); - free (remote); return -1; } if (close (fd) == -1) { perror (filename); - unlink (filename); - free (remote); return -1; } @@ -93,13 +86,10 @@ run_more (const char *cmd, size_t argc, char *argv[]) snprintf (buf, sizeof buf, "%s %s", pager, filename); r = system (buf); - unlink (filename); if (r != 0) { perror (buf); - free (remote); return -1; } - free (remote); return 0; } diff --git a/fish/options.c b/fish/options.c index 40671b5f6..384ef43e4 100644 --- a/fish/options.c +++ b/fish/options.c @@ -138,16 +138,11 @@ static void display_mountpoints_on_failure (const char *mp_device, const char *user_supplied_options) { - char **fses, *p; + CLEANUP_FREE_STRING_LIST char **fses = guestfs_list_filesystems (g); size_t i; - fses = guestfs_list_filesystems (g); - if (fses == NULL) + if (fses == NULL || fses[0] == NULL) return; - if (fses[0] == NULL) { - free (fses); - return; - } fprintf (stderr, _("%s: '%s' could not be mounted.\n"), program_name, mp_device); @@ -161,15 +156,10 @@ display_mountpoints_on_failure (const char *mp_device, program_name); for (i = 0; fses[i] != NULL; i += 2) { - p = guestfs_canonical_device_name (g, fses[i]); + CLEANUP_FREE char *p = guestfs_canonical_device_name (g, fses[i]); fprintf (stderr, "%s: \t%s (%s)\n", program_name, p ? p : fses[i], fses[i+1]); - free (p); - free (fses[i]); - free (fses[i+1]); } - - free (fses); } void diff --git a/fish/prep-boot.c b/fish/prep-boot.c index 75ddcca42..426c50bad 100644 --- a/fish/prep-boot.c +++ b/fish/prep-boot.c @@ -60,7 +60,7 @@ prep_postlaunch_bootroot (const char *filename, prep_data *data, const char *dev prep_error (data, filename, _("failed to add root partition: %s"), guestfs_last_error (g)); - char *part; + CLEANUP_FREE char *part; if (asprintf (&part, "%s1", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); @@ -68,16 +68,15 @@ prep_postlaunch_bootroot (const char *filename, prep_data *data, const char *dev if (guestfs_mkfs (g, data->params[0], part) == -1) prep_error (data, filename, _("failed to create boot filesystem: %s"), guestfs_last_error (g)); - free (part); - if (asprintf (&part, "%s2", device) == -1) { + CLEANUP_FREE char *part2; + if (asprintf (&part2, "%s2", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); } - if (guestfs_mkfs (g, data->params[1], part) == -1) + if (guestfs_mkfs (g, data->params[1], part2) == -1) prep_error (data, filename, _("failed to create root filesystem: %s"), guestfs_last_error (g)); - free (part); } void @@ -115,12 +114,12 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *d prep_error (data, filename, _("failed to add root partition: %s"), guestfs_last_error (g)); - char *vg; - char *lv; + CLEANUP_FREE char *vg; + CLEANUP_FREE char *lv; if (vg_lv_parse (data->params[0], &vg, &lv) == -1) prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'")); - char *part; + CLEANUP_FREE char *part; if (asprintf (&part, "%s1", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); @@ -128,17 +127,17 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *d if (guestfs_mkfs (g, data->params[1], part) == -1) prep_error (data, filename, _("failed to create boot filesystem: %s"), guestfs_last_error (g)); - free (part); - if (asprintf (&part, "%s2", device) == -1) { + CLEANUP_FREE char *part2; + if (asprintf (&part2, "%s2", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); } - if (guestfs_pvcreate (g, part) == -1) + if (guestfs_pvcreate (g, part2) == -1) prep_error (data, filename, _("failed to create PV: %s: %s"), - part, guestfs_last_error (g)); + part2, guestfs_last_error (g)); - char *parts[] = { part, NULL }; + char *parts[] = { part2, NULL }; if (guestfs_vgcreate (g, vg, parts) == -1) prep_error (data, filename, _("failed to create VG: %s: %s"), vg, guestfs_last_error (g)); @@ -151,8 +150,4 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *d if (guestfs_mkfs (g, data->params[2], data->params[0]) == -1) prep_error (data, filename, _("failed to create root filesystem: %s"), guestfs_last_error (g)); - - free (part); - free (vg); - free (lv); } diff --git a/fish/prep-fs.c b/fish/prep-fs.c index a0373d9c3..49f449a0d 100644 --- a/fish/prep-fs.c +++ b/fish/prep-fs.c @@ -42,7 +42,7 @@ prep_postlaunch_fs (const char *filename, prep_data *data, const char *device) prep_error (data, filename, _("failed to partition disk: %s"), guestfs_last_error (g)); - char *part; + CLEANUP_FREE char *part; if (asprintf (&part, "%s1", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); @@ -51,6 +51,4 @@ prep_postlaunch_fs (const char *filename, prep_data *data, const char *device) if (guestfs_mkfs (g, data->params[0], part) == -1) prep_error (data, filename, _("failed to create filesystem (%s): %s"), data->params[0], guestfs_last_error (g)); - - free (part); } diff --git a/fish/prep-lv.c b/fish/prep-lv.c index f635ff9fe..a9b7b700e 100644 --- a/fish/prep-lv.c +++ b/fish/prep-lv.c @@ -77,12 +77,12 @@ prep_postlaunch_lv (const char *filename, prep_data *data, const char *device) prep_error (data, filename, _("failed to partition disk: %s"), guestfs_last_error (g)); - char *vg; - char *lv; + CLEANUP_FREE char *vg; + CLEANUP_FREE char *lv; if (vg_lv_parse (data->params[0], &vg, &lv) == -1) prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'")); - char *part; + CLEANUP_FREE char *part; if (asprintf (&part, "%s1", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); @@ -101,10 +101,6 @@ prep_postlaunch_lv (const char *filename, prep_data *data, const char *device) if (guestfs_lvcreate_free (g, lv, vg, 100) == -1) prep_error (data, filename, _("failed to create LV: /dev/%s/%s: %s"), vg, lv, guestfs_last_error (g)); - - free (part); - free (vg); - free (lv); } void @@ -124,12 +120,12 @@ prep_postlaunch_lvfs (const char *filename, prep_data *data, const char *device) prep_error (data, filename, _("failed to partition disk: %s"), guestfs_last_error (g)); - char *vg; - char *lv; + CLEANUP_FREE char *vg; + CLEANUP_FREE char *lv; if (vg_lv_parse (data->params[0], &vg, &lv) == -1) prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'")); - char *part; + CLEANUP_FREE char *part; if (asprintf (&part, "%s1", device) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); @@ -153,8 +149,4 @@ prep_postlaunch_lvfs (const char *filename, prep_data *data, const char *device) if (guestfs_mkfs (g, data->params[1], data->params[0]) == -1) prep_error (data, filename, _("failed to create filesystem (%s): %s"), data->params[1], guestfs_last_error (g)); - - free (part); - free (vg); - free (lv); } diff --git a/fish/supported.c b/fish/supported.c index c3a15c8f1..64b52943d 100644 --- a/fish/supported.c +++ b/fish/supported.c @@ -29,10 +29,8 @@ int run_supported (const char *cmd, size_t argc, char *argv[]) { - char **groups; - /* As a side-effect this also checks that we've called 'launch'. */ - groups = guestfs_available_all_groups (g); + CLEANUP_FREE_STRING_LIST char **groups = guestfs_available_all_groups (g); if (groups == NULL) return -1; @@ -67,11 +65,6 @@ run_supported (const char *cmd, size_t argc, char *argv[]) putchar ('\n'); } - /* Free groups list. */ - for (i = 0; groups[i] != NULL; ++i) - free (groups[i]); - free (groups); - /* Restore error handler. */ guestfs_pop_error_handler (g);