Skip to content

Commit e0de235

Browse files
committed
fix: fix cgo memory leak
1 parent 0f004a2 commit e0de235

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

perf/collector_libpfm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,12 @@ func readPerfEventAttr(name string, pfmGetOsEventEncoding func(string, unsafe.Po
266266
func pfmGetOsEventEncoding(name string, perfEventAttrMemory unsafe.Pointer) error {
267267
event := pfmPerfEncodeArgT{}
268268
fstr := C.CString("")
269+
defer C.free(unsafe.Pointer(fstr))
269270
event.fstr = unsafe.Pointer(fstr)
270271
event.attr = perfEventAttrMemory
271272
event.size = C.ulong(unsafe.Sizeof(event))
272273
cSafeName := C.CString(name)
274+
defer C.free(unsafe.Pointer(cSafeName))
273275
pErr := C.pfm_get_os_event_encoding(cSafeName, C.PFM_PLM0|C.PFM_PLM3, C.PFM_OS_PERF_EVENT, unsafe.Pointer(&event))
274276
if pErr != C.PFM_SUCCESS {
275277
return fmt.Errorf("unable to transform event name %s to perf_event_attr: %d", name, int(pErr))

0 commit comments

Comments
 (0)