summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-07-03 11:07:13 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-06 17:36:30 +0100
commit7e84471abbfbb2f778813b08effe3d72e547721b (patch)
tree7b2210ba29824dfe0a8c66dffc3c17a6a6ba5e17
parent65d1f27ff2362be16433e603ed8a1e690249d278 (diff)
downloadlibguestfs-7e84471abbfbb2f778813b08effe3d72e547721b.tar.gz
libguestfs-7e84471abbfbb2f778813b08effe3d72e547721b.tar.xz
libguestfs-7e84471abbfbb2f778813b08effe3d72e547721b.zip
close: Rearrange the order in which the handle is closed and freed.
The order is now: - remove the handle from the list of handles - send close trace message - sync and shutdown qemu - run user close callback - free temporary directory - free memory This commit ought to be no functional change. (cherry picked from commit fc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1)
-rw-r--r--src/guestfs.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index f296a0c4..ab11a140 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -178,6 +178,19 @@ guestfs_close (guestfs_h *g)
return;
}
+ /* Remove the handle from the handles list. */
+ gl_lock_lock (handles_lock);
+ if (handles == g)
+ handles = g->next;
+ else {
+ guestfs_h *gg;
+
+ for (gg = handles; gg->next != g; gg = gg->next)
+ ;
+ gg->next = g->next;
+ }
+ gl_lock_unlock (handles_lock);
+
if (g->trace) {
const char trace_msg[] = "close";
@@ -203,19 +216,6 @@ guestfs_close (guestfs_h *g)
ignore_value (guestfs_kill_subprocess (g));
#endif
- /* Run user close callbacks. */
- guestfs___call_callbacks_void (g, GUESTFS_EVENT_CLOSE);
-
- /* Remove all other registered callbacks. Since we've already
- * called the close callbacks, we shouldn't call any others.
- */
- free (g->events);
- g->nr_events = 0;
- g->events = NULL;
-
- guestfs___free_inspect_info (g);
- guestfs___free_drives (&g->drives);
-
/* Close sockets. */
if (g->fd[0] >= 0)
close (g->fd[0]);
@@ -231,9 +231,25 @@ guestfs_close (guestfs_h *g)
if (g->pid > 0) waitpid (g->pid, NULL, 0);
if (g->recoverypid > 0) waitpid (g->recoverypid, NULL, 0);
+ /* Run user close callbacks. */
+ guestfs___call_callbacks_void (g, GUESTFS_EVENT_CLOSE);
+
/* Remove whole temporary directory. */
guestfs___remove_tmpdir (g->tmpdir);
- free (g->tmpdir);
+
+ /* Mark the handle as dead and then free up all memory. */
+ g->state = NO_HANDLE;
+
+ free (g->events);
+ g->nr_events = 0;
+ g->events = NULL;
+
+#if HAVE_FUSE
+ guestfs___free_fuse (g);
+#endif
+
+ guestfs___free_inspect_info (g);
+ guestfs___free_drives (&g->drives);
if (g->cmdline) {
size_t i;
@@ -243,27 +259,9 @@ guestfs_close (guestfs_h *g)
free (g->cmdline);
}
- /* Mark the handle as dead before freeing it. */
- g->state = NO_HANDLE;
-
- gl_lock_lock (handles_lock);
- if (handles == g)
- handles = g->next;
- else {
- guestfs_h *gg;
-
- for (gg = handles; gg->next != g; gg = gg->next)
- ;
- gg->next = g->next;
- }
- gl_lock_unlock (handles_lock);
-
-#if HAVE_FUSE
- guestfs___free_fuse (g);
-#endif
-
if (g->pda)
hash_free (g->pda);
+ free (g->tmpdir);
free (g->last_error);
free (g->path);
free (g->qemu);