Skip to content

Commit 400a453

Browse files
authored
Merge pull request #1360 from bduffany/darwin-memleak
Fix memory leaks in process_darwin_cgo
2 parents 769daaf + 3806460 commit 400a453

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

process/process_darwin_cgo.go

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
175175
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
176176
const tiSize = C.sizeof_struct_proc_taskinfo
177177
ti := (*C.struct_proc_taskinfo)(C.malloc(tiSize))
178+
defer C.free(unsafe.Pointer(ti))
178179

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

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

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

0 commit comments

Comments
 (0)