Commit aba6f064 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Only clear internal pointer if refcount hit zero

Signed-off-by: 's avatarDaniel P. Berrange <berrange@redhat.com>
parent 72e17467
......@@ -861,10 +861,12 @@ type DomainVcpuInfo struct {
}
func (d *Domain) Free() error {
if result := C.virDomainFree(d.ptr); result != 0 {
ret := C.virDomainFree(d.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
d.ptr = nil
}
d.ptr = nil
return nil
}
......
......@@ -90,10 +90,12 @@ type DomainSnapshot struct {
}
func (s *DomainSnapshot) Free() error {
if result := C.virDomainSnapshotFree(s.ptr); result != 0 {
ret := C.virDomainSnapshotFree(s.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
s.ptr = nil
}
s.ptr = nil
return nil
}
......
......@@ -112,10 +112,12 @@ func (n *Interface) Undefine() error {
}
func (n *Interface) Free() error {
if result := C.virInterfaceFree(n.ptr); result != 0 {
ret := C.virInterfaceFree(n.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
n.ptr = nil
}
n.ptr = nil
return nil
}
......
......@@ -122,10 +122,12 @@ type NetworkDHCPLease struct {
}
func (n *Network) Free() error {
if result := C.virNetworkFree(n.ptr); result != 0 {
ret := C.virNetworkFree(n.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
n.ptr = nil
}
n.ptr = nil
return nil
}
......
......@@ -58,10 +58,12 @@ type NodeDevice struct {
}
func (n *NodeDevice) Free() error {
if result := C.virNodeDeviceFree(n.ptr); result != 0 {
ret := C.virNodeDeviceFree(n.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
n.ptr = nil
}
n.ptr = nil
return nil
}
......
......@@ -43,10 +43,12 @@ type NWFilter struct {
}
func (f *NWFilter) Free() error {
if result := C.virNWFilterFree(f.ptr); result != 0 {
ret := C.virNWFilterFree(f.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
f.ptr = nil
}
f.ptr = nil
return nil
}
......
......@@ -68,10 +68,12 @@ type Secret struct {
}
func (s *Secret) Free() error {
if result := C.virSecretFree(s.ptr); result != 0 {
ret := C.virSecretFree(s.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
s.ptr = nil
}
s.ptr = nil
return nil
}
......
......@@ -136,10 +136,12 @@ func (p *StoragePool) Destroy() error {
}
func (p *StoragePool) Free() error {
if result := C.virStoragePoolFree(p.ptr); result != 0 {
ret := C.virStoragePoolFree(p.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
p.ptr = nil
}
p.ptr = nil
return nil
}
......
......@@ -120,10 +120,12 @@ func (v *StorageVol) Delete(flags StorageVolDeleteFlags) error {
}
func (v *StorageVol) Free() error {
if result := C.virStorageVolFree(v.ptr); result != 0 {
ret := C.virStorageVolFree(v.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
v.ptr = nil
}
v.ptr = nil
return nil
}
......
......@@ -77,11 +77,12 @@ func (v *Stream) Finish() error {
}
func (v *Stream) Free() error {
result := C.virStreamFree(v.ptr)
if result == -1 {
ret := C.virStreamFree(v.ptr)
if ret == -1 {
return GetLastError()
} else if ret == 0 {
v.ptr = nil
}
v.ptr = nil
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment