mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 05:55:19 +00:00
virsh: Unregister the connection close notifier upon termination
Before closing the connection we unregister the close callback
to prevent a reference leak.
Further, the messages on virConnectClose != 0 are a bit more specific
now.
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
(cherry picked from commit e964ba2786
)
This commit is contained in:
parent
cf7dbdd42a
commit
bec3cc7308
@ -321,9 +321,18 @@ vshReconnect(vshControl *ctl)
|
|||||||
{
|
{
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
if (ctl->conn != NULL) {
|
if (ctl->conn) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
connected = true;
|
connected = true;
|
||||||
virConnectClose(ctl->conn);
|
|
||||||
|
virConnectUnregisterCloseCallback(ctl->conn, vshCatchDisconnect);
|
||||||
|
ret = virConnectClose(ctl->conn);
|
||||||
|
if (ret < 0)
|
||||||
|
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
|
||||||
|
else if (ret > 0)
|
||||||
|
vshError(ctl, "%s", _("One or more references were leaked after "
|
||||||
|
"disconnect from the hypervisor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl->conn = virConnectOpenAuth(ctl->name,
|
ctl->conn = virConnectOpenAuth(ctl->name,
|
||||||
@ -2660,9 +2669,13 @@ vshDeinit(vshControl *ctl)
|
|||||||
VIR_FREE(ctl->name);
|
VIR_FREE(ctl->name);
|
||||||
if (ctl->conn) {
|
if (ctl->conn) {
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = virConnectClose(ctl->conn)) != 0) {
|
virConnectUnregisterCloseCallback(ctl->conn, vshCatchDisconnect);
|
||||||
vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
|
ret = virConnectClose(ctl->conn);
|
||||||
}
|
if (ret < 0)
|
||||||
|
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
|
||||||
|
else if (ret > 0)
|
||||||
|
vshError(ctl, "%s", _("One or more references were leaked after "
|
||||||
|
"disconnect from the hypervisor"));
|
||||||
}
|
}
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user