diff --git a/migration.c b/migration.c
index f5959b4..a432c3b 100644
--- a/migration.c
+++ b/migration.c
@@ -286,6 +286,13 @@ int migrate_fd_cleanup(FdMigrationState *s)
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if ((s->state == MIG_STATE_ERROR ||
+         s->state == MIG_STATE_CANCELLED) &&
+        s->fd != -1) {
+        close(s->fd);
+        s->fd = -1;
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         if (qemu_fclose(s->file) != 0) {
