Skip to content

Possible memory leak of cgroup in Domain.DelThrottleGroup #2

Description

@OvOhao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions