Skip to content

Commit 248756c

Browse files
authored
Merge pull request #3346 from Rouzip/fix-cgo
2 parents 0f004a2 + 4852908 commit 248756c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

perf/collector_libpfm.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ type group struct {
6262

6363
var (
6464
isLibpfmInitialized = false
65-
libpmfMutex = sync.Mutex{}
65+
libpfmMutex = sync.Mutex{}
6666
)
6767

6868
const (
6969
groupLeaderFileDescriptor = -1
7070
)
7171

7272
func init() {
73-
libpmfMutex.Lock()
74-
defer libpmfMutex.Unlock()
73+
libpfmMutex.Lock()
74+
defer libpfmMutex.Unlock()
7575
pErr := C.pfm_initialize()
7676
if pErr != C.PFM_SUCCESS {
7777
klog.Errorf("unable to initialize libpfm: %d", int(pErr))
@@ -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))
@@ -409,8 +411,8 @@ func (c *collector) Destroy() {
409411

410412
// Finalize terminates libpfm4 to free resources.
411413
func Finalize() {
412-
libpmfMutex.Lock()
413-
defer libpmfMutex.Unlock()
414+
libpfmMutex.Lock()
415+
defer libpfmMutex.Unlock()
414416

415417
klog.V(1).Info("Attempting to terminate libpfm4")
416418
if !isLibpfmInitialized {

0 commit comments

Comments
 (0)