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-03 14:45:42 +0100
commitfc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1 (patch)
tree815edf26678483fa23dfa8bca7a6e7dfcdb9bc4f
parent27ebf517fae972eee49ae5911a03fabe5f4b6e54 (diff)
downloadlibguestfs-fc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1.tar.gz
libguestfs-fc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1.tar.xz
libguestfs-fc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1.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.
-rw-r--r--src/guestfs.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 32bcbeff..16d11dae 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);