From: "Richard W.M. Jones" <rjones@redhat.com> --- src/inspect-fs.c | 17 ++++------------- src/inspect.c | 8 ++------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/inspect-fs.c b/src/inspect-fs.c index fed7761..724d4ee 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -89,7 +89,6 @@ int guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, int is_block, int is_partnum) { - char *vfs_type; int is_swap, r; struct inspect_fs *fs; @@ -98,7 +97,7 @@ guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, * temporarily replace the error handler with a null one. */ guestfs_push_error_handler (g, NULL, NULL); - vfs_type = guestfs_vfs_type (g, device); + CLEANUP_FREE (char *, vfs_type, guestfs_vfs_type (g, device)); guestfs_pop_error_handler (g); is_swap = vfs_type && STREQ (vfs_type, "swap"); @@ -108,7 +107,6 @@ guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, vfs_type ? vfs_type : "failed to get vfs type"); if (is_swap) { - free (vfs_type); if (extend_fses (g) == -1) return -1; fs = &g->fses[g->nr_fses-1]; @@ -145,7 +143,6 @@ guestfs___check_for_filesystem_on (guestfs_h *g, const char *device, } else { r = guestfs_mount_ro (g, device, "/"); } - free (vfs_type); guestfs_pop_error_handler (g); if (r == -1) return 0; @@ -341,28 +338,24 @@ extend_fses (guestfs_h *g) int guestfs___is_file_nocase (guestfs_h *g, const char *path) { - char *p; int r; - p = guestfs___case_sensitive_path_silently (g, path); + CLEANUP_FREE (char *, p, guestfs___case_sensitive_path_silently (g, path)); if (!p) return 0; r = guestfs_is_file (g, p); - free (p); return r > 0; } int guestfs___is_dir_nocase (guestfs_h *g, const char *path) { - char *p; int r; - p = guestfs___case_sensitive_path_silently (g, path); + CLEANUP_FREE (char *, p, guestfs___case_sensitive_path_silently (g, path)); if (!p) return 0; r = guestfs_is_dir (g, p); - free (p); return r > 0; } @@ -532,7 +525,6 @@ guestfs___check_package_management (guestfs_h *g, struct inspect_fs *fs) char * guestfs___first_line_of_file (guestfs_h *g, const char *filename) { - char **lines; int64_t size; char *ret; @@ -549,7 +541,7 @@ guestfs___first_line_of_file (guestfs_h *g, const char *filename) return NULL; } - lines = guestfs_head_n (g, 1, filename); + CLEANUP_FREE (char **, lines, guestfs_head_n (g, 1, filename)); if (lines == NULL) return NULL; if (lines[0] == NULL) { @@ -560,7 +552,6 @@ guestfs___first_line_of_file (guestfs_h *g, const char *filename) /* lines[1] should be NULL because of '1' argument above ... */ ret = lines[0]; /* caller frees */ - free (lines); /* free the array */ return ret; } diff --git a/src/inspect.c b/src/inspect.c index 30e9762..f165957 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -143,23 +143,19 @@ guestfs__inspect_os (guestfs_h *g) static int parent_device_already_probed (guestfs_h *g, const char *partition) { - char *device; size_t i; guestfs_push_error_handler (g, NULL, NULL); - device = guestfs_part_to_dev (g, partition); + CLEANUP_FREE (char *, device, guestfs_part_to_dev (g, partition)); guestfs_pop_error_handler (g); if (!device) return 0; for (i = 0; i < g->nr_fses; ++i) { - if (STREQ (device, g->fses[i].device)) { - free (device); + if (STREQ (device, g->fses[i].device)) return 1; - } } - free (device); return 0; } -- 1.8.1