X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fappliance.c;h=57ff38f1f1064e47a2bf08b0ea27eed9ecd7c964;hb=da13c1c0e6980f4838090be9e775b4d5c35662b7;hp=1df8c3616c97d1b85e4cdb613087bd0d40d13b09;hpb=635af5be04265f845186b40e9a9fe7b102ad6909;p=libguestfs.git diff --git a/src/appliance.c b/src/appliance.c index 1df8c36..57ff38f 100644 --- a/src/appliance.c +++ b/src/appliance.c @@ -241,7 +241,7 @@ calculate_supermin_checksum (guestfs_h *g, const char *supermin_path) return NULL; } - if (pclose (pp) == -1) { + if (pclose (pp) != 0) { warning (g, "pclose: %m"); return NULL; } @@ -402,6 +402,12 @@ check_for_cached_appliance (guestfs_h *g, /* Releases the lock on checksum. */ if (close (fd) == -1) { perrorf (g, "close"); + /* Allocated in hard_link_to_cached_appliance above, must be + * freed along this error path. + */ + free (*kernel); + free (*initrd); + free (*appliance); return -1; } @@ -444,8 +450,10 @@ build_supermin_appliance (guestfs_h *g, guestfs___print_timestamped_message (g, "run febootstrap-supermin-helper"); int r = run_supermin_helper (g, supermin_path, tmpcd, len); - if (r == -1) + if (r == -1) { + guestfs___remove_tmpdir (tmpcd); return -1; + } if (g->verbose) guestfs___print_timestamped_message (g, "finished building supermin appliance"); @@ -462,6 +470,7 @@ build_supermin_appliance (guestfs_h *g, int fd = open (filename, O_WRONLY|O_CREAT, 0755); if (fd == -1) { perrorf (g, "open: %s", filename); + guestfs___remove_tmpdir (tmpcd); return -1; } struct flock fl; @@ -475,6 +484,7 @@ build_supermin_appliance (guestfs_h *g, goto again; perrorf (g, "fcntl: F_SETLKW: %s", filename); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } @@ -486,6 +496,7 @@ build_supermin_appliance (guestfs_h *g, if (ftruncate (fd, clen) == -1) { perrorf (g, "ftruncate: %s", filename); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } @@ -493,11 +504,13 @@ build_supermin_appliance (guestfs_h *g, if (rr == -1) { perrorf (g, "write: %s", filename); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } if ((size_t) rr != clen) { error (g, "partial write: %s", filename); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } @@ -507,6 +520,7 @@ build_supermin_appliance (guestfs_h *g, if (rename (filename, filename2) == -1) { perrorf (g, "rename: %s %s", filename, filename2); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } @@ -516,6 +530,7 @@ build_supermin_appliance (guestfs_h *g, if (rename (filename, filename2) == -1) { perrorf (g, "rename: %s %s", filename, filename2); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } @@ -525,10 +540,11 @@ build_supermin_appliance (guestfs_h *g, if (rename (filename, filename2) == -1) { perrorf (g, "rename: %s %s", filename, filename2); close (fd); + guestfs___remove_tmpdir (tmpcd); return -1; } - rmdir (tmpcd); + guestfs___remove_tmpdir (tmpcd); /* Now finish off by linking to the cached appliance and returning it. */ if (hard_link_to_cached_appliance (g, cachedir, @@ -540,6 +556,12 @@ build_supermin_appliance (guestfs_h *g, /* Releases the lock on checksum. */ if (close (fd) == -1) { perrorf (g, "close"); + /* Allocated in hard_link_to_cached_appliance above, must be + * freed along this error path. + */ + free (*kernel); + free (*initrd); + free (*appliance); return -1; }