Possible memory leak of cgroup in Domain.DelThrottleGroup
DelThrottleGroup allocates the group name with C.CString but never frees it, so
every call leaks len(group)+1 bytes.
domain.go:6082
func (d *Domain) DelThrottleGroup(group string, flags DomainModificationImpact) error {
var err C.virError
cgroup := C.CString(group)
ret := C.virDomainDelThrottleGroupWrapper(d.ptr, cgroup, C.uint(flags), &err)
if ret == -1 {
return makeError(&err)
}
return nil
}
virDomainDelThrottleGroup takes const char *group and copies what it needs, so the
caller keeps ownership. cgroup is a local that is never stored or returned, so nothing
else can free it either. Both the error return and the success return drop it.
The rest of the file already does this correctly. Of the 73 C.CString calls in
domain.go, 71 are followed by defer C.free; this one and SetThrottleGroup at line
6103 are the only two that are not.
Fix:
cgroup := C.CString(group)
defer C.free(unsafe.Pointer(cgroup))
SetThrottleGroup needs the same change; I have opened a separate issue for it.
If you could credit me as a reporter for my contributions to security advisory I will be thankful.
Possible memory leak of
cgroupinDomain.DelThrottleGroupDelThrottleGroupallocates the group name withC.CStringbut never frees it, soevery call leaks
len(group)+1bytes.domain.go:6082
virDomainDelThrottleGrouptakesconst char *groupand copies what it needs, so thecaller keeps ownership.
cgroupis a local that is never stored or returned, so nothingelse can free it either. Both the error return and the success return drop it.
The rest of the file already does this correctly. Of the 73
C.CStringcalls indomain.go, 71 are followed by
defer C.free; this one andSetThrottleGroupat line6103 are the only two that are not.
Fix:
SetThrottleGroupneeds the same change; I have opened a separate issue for it.If you could credit me as a reporter for my contributions to security advisory I will be thankful.