Skip to content

Possible memory leak of cgroup in Domain.SetThrottleGroup #3

Description

@OvOhao

Possible memory leak of cgroup in Domain.SetThrottleGroup

Same problem as DelThrottleGroup: cgroup is allocated with C.CString and never
freed. Every call leaks len(group)+1 bytes.

domain.go:6093

func (d *Domain) SetThrottleGroup(group string, params *DomainBlockIoTuneParameters, flags DomainModificationImpact) error {
	info := getBlockIoTuneParametersFieldInfo(params)
	cparams, cnparams, gerr := typedParamsPackNew(info)
	if gerr != nil {
		return gerr
	}

	defer C.virTypedParamsFreeWrapper(cparams, cnparams)

	var err C.virError
	cgroup := C.CString(group)
	ret := C.virDomainSetThrottleGroupWrapper(d.ptr, cgroup, cparams, cnparams, C.uint(flags), &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}

Note the cparams on the line above is released with a defer, but cgroup is not.
libvirt takes the group name as const char * and copies it, so the caller owns the
buffer. cgroup is a local, so no other function can reach it after the return.

Fix:

	cgroup := C.CString(group)
	defer C.free(unsafe.Pointer(cgroup))

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