diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-08-28 17:48:19 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-08-28 17:49:46 +0100 |
commit | 9ef36632ca76ea11b5227e977a9fb9db3fad0d01 (patch) | |
tree | 584b45c4fd372d4b434790c44d84fa87d9cb8f51 /src/launch-libvirt.c | |
parent | cab48ce73cb19b1aa8784e6c6a3cb8f47b0cbc0e (diff) | |
download | libguestfs-9ef36632ca76ea11b5227e977a9fb9db3fad0d01.tar.gz libguestfs-9ef36632ca76ea11b5227e977a9fb9db3fad0d01.tar.xz libguestfs-9ef36632ca76ea11b5227e977a9fb9db3fad0d01.zip |
launch: libvirt: Don't crash if shutdown_libvirt is called early in launch.
The assert (conn != NULL) was being triggered with this
stack trace:
at launch-libvirt.c:1305
fd=<optimized out>, error_if_eof=error_if_eof@entry=0) at proto.c:222
size_rtn=size_rtn@entry=0x7fffffffdb34,
buf_rtn=buf_rtn@entry=0x7fffffffdb58) at proto.c:548
libvirt_uri=<optimized out>) at launch-libvirt.c:391
Diffstat (limited to 'src/launch-libvirt.c')
-rw-r--r-- | src/launch-libvirt.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index f5f641a4..760c99f2 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -1302,16 +1302,21 @@ shutdown_libvirt (guestfs_h *g) virDomainPtr dom = g->virt.domv; int ret = 0; - assert (conn != NULL); - assert (dom != NULL); + /* Note that we can be called back very early in launch (specifically + * from launch_libvirt itself), when conn and dom might be NULL. + */ - /* XXX Need to be graceful? */ - if (virDomainDestroyFlags (dom, 0) == -1) { - libvirt_error (g, _("could not destroy libvirt domain")); - ret = -1; + if (dom != NULL) { + /* XXX Need to be graceful? */ + if (virDomainDestroyFlags (dom, 0) == -1) { + libvirt_error (g, _("could not destroy libvirt domain")); + ret = -1; + } + virDomainFree (dom); } - virDomainFree (dom); - virConnectClose (conn); + + if (conn != NULL) + virConnectClose (conn); g->virt.connv = g->virt.domv = NULL; |