Fix mkdir-p if directory exists (RHBZ#503133).
[libguestfs.git] / daemon / tar.c
index ecf919d..9f4813c 100644 (file)
@@ -68,8 +68,10 @@ do_tar_in (const char *dir)
     cancel_receive ();
     errno = err;
     reply_with_perror ("%s", cmd);
+    free (cmd);
     return -1;
   }
+  free (cmd);
 
   r = receive_file (fwrite_cb, &fp);
   if (r == -1) {               /* write error */
@@ -123,8 +125,10 @@ do_tar_out (const char *dir)
   fp = popen (cmd, "r");
   if (fp == NULL) {
     reply_with_perror ("%s", cmd);
+    free (cmd);
     return -1;
   }
+  free (cmd);
 
   /* Now we must send the reply message, before the file contents.  After
    * this there is no opportunity in the protocol to send any error
@@ -139,7 +143,7 @@ do_tar_out (const char *dir)
     }
   }
 
-  if (r == -1) {
+  if (ferror (fp)) {
     perror (dir);
     send_file_end (1);         /* Cancel. */
     pclose (fp);
@@ -190,8 +194,10 @@ do_tgz_in (const char *dir)
     cancel_receive ();
     errno = err;
     reply_with_perror ("%s", cmd);
+    free (cmd);
     return -1;
   }
+  free (cmd);
 
   r = receive_file (fwrite_cb, &fp);
   if (r == -1) {               /* write error */
@@ -245,8 +251,10 @@ do_tgz_out (const char *dir)
   fp = popen (cmd, "r");
   if (fp == NULL) {
     reply_with_perror ("%s", cmd);
+    free (cmd);
     return -1;
   }
+  free (cmd);
 
   /* Now we must send the reply message, before the file contents.  After
    * this there is no opportunity in the protocol to send any error
@@ -261,7 +269,7 @@ do_tgz_out (const char *dir)
     }
   }
 
-  if (r == -1) {
+  if (ferror (fp)) {
     perror (dir);
     send_file_end (1);         /* Cancel. */
     pclose (fp);