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-07 11:29:40 +0100
commitced9e9840715c8dab85465611fc566fc5d1a4df1 (patch)
treea84375e2c9558e028c866206d04736a6805cef4b
parentfccf6929549abdaa7405b6d0f68187575f4e9300 (diff)
downloadlibguestfs-ced9e9840715c8dab85465611fc566fc5d1a4df1.tar.gz
libguestfs-ced9e9840715c8dab85465611fc566fc5d1a4df1.tar.xz
libguestfs-ced9e9840715c8dab85465611fc566fc5d1a4df1.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.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 32cf60eb..4e66e17e 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,21 @@ 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;
+
+ guestfs___free_inspect_info (g);
+ guestfs___free_drives (&g->drives);
if (g->cmdline) {
size_t i;
@@ -243,23 +255,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 (g->pda)
hash_free (g->pda);
+ free (g->tmpdir);
free (g->last_error);
free (g->path);
free (g->qemu);