@@ -175,6 +175,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
175
175
func (p * Process ) NumThreadsWithContext (ctx context.Context ) (int32 , error ) {
176
176
const tiSize = C .sizeof_struct_proc_taskinfo
177
177
ti := (* C .struct_proc_taskinfo )(C .malloc (tiSize ))
178
+ defer C .free (unsafe .Pointer (ti ))
178
179
179
180
_ , err := C .proc_pidinfo (C .int (p .Pid ), C .PROC_PIDTASKINFO , 0 , unsafe .Pointer (ti ), tiSize )
180
181
if err != nil {
@@ -187,6 +188,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
187
188
func (p * Process ) TimesWithContext (ctx context.Context ) (* cpu.TimesStat , error ) {
188
189
const tiSize = C .sizeof_struct_proc_taskinfo
189
190
ti := (* C .struct_proc_taskinfo )(C .malloc (tiSize ))
191
+ defer C .free (unsafe .Pointer (ti ))
190
192
191
193
_ , err := C .proc_pidinfo (C .int (p .Pid ), C .PROC_PIDTASKINFO , 0 , unsafe .Pointer (ti ), tiSize )
192
194
if err != nil {
@@ -204,6 +206,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
204
206
func (p * Process ) MemoryInfoWithContext (ctx context.Context ) (* MemoryInfoStat , error ) {
205
207
const tiSize = C .sizeof_struct_proc_taskinfo
206
208
ti := (* C .struct_proc_taskinfo )(C .malloc (tiSize ))
209
+ defer C .free (unsafe .Pointer (ti ))
207
210
208
211
_ , err := C .proc_pidinfo (C .int (p .Pid ), C .PROC_PIDTASKINFO , 0 , unsafe .Pointer (ti ), tiSize )
209
212
if err != nil {
0 commit comments