Skip to content

Commit

Permalink
Merge pull request #1360 from bduffany/darwin-memleak
Browse files Browse the repository at this point in the history
Fix memory leaks in process_darwin_cgo
  • Loading branch information
shirou committed Oct 9, 2022
2 parents 769daaf + 3806460 commit 400a453
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions process/process_darwin_cgo.go
Expand Up @@ -175,6 +175,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
const tiSize = C.sizeof_struct_proc_taskinfo
ti := (*C.struct_proc_taskinfo)(C.malloc(tiSize))
defer C.free(unsafe.Pointer(ti))

_, err := C.proc_pidinfo(C.int(p.Pid), C.PROC_PIDTASKINFO, 0, unsafe.Pointer(ti), tiSize)
if err != nil {
Expand All @@ -187,6 +188,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
const tiSize = C.sizeof_struct_proc_taskinfo
ti := (*C.struct_proc_taskinfo)(C.malloc(tiSize))
defer C.free(unsafe.Pointer(ti))

_, err := C.proc_pidinfo(C.int(p.Pid), C.PROC_PIDTASKINFO, 0, unsafe.Pointer(ti), tiSize)
if err != nil {
Expand All @@ -204,6 +206,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
const tiSize = C.sizeof_struct_proc_taskinfo
ti := (*C.struct_proc_taskinfo)(C.malloc(tiSize))
defer C.free(unsafe.Pointer(ti))

_, err := C.proc_pidinfo(C.int(p.Pid), C.PROC_PIDTASKINFO, 0, unsafe.Pointer(ti), tiSize)
if err != nil {
Expand Down

0 comments on commit 400a453

Please sign in to comment.