-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add PssFreeSnapshot #115
add PssFreeSnapshot #115
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,10 @@ func FetchNumThreads(pid int) (int, error) { | |
if err != nil { | ||
return 0, fmt.Errorf("PssCaptureSnapshot failed: %w", err) | ||
} | ||
defer func() { | ||
cHandle, _ := syscall.GetCurrentProcess() | ||
PssFreeSnapshot(cHandle, snapshotHandle) | ||
}() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only possible issue with putting this in a defer is that if If the memory here is allocated in the memory of the current process this won't matter as it'll all be freed on exit, if the memory is held by the kernel then I'm not sure what happens. Hopefully it is also freed because it is associated with the existence of this process in some way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be safer to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to free after query, regardless of query return code. |
||
|
||
info := PssThreadInformation{} | ||
buffSize := unsafe.Sizeof(info) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the errors should be returned to caller of FetchNumThreads. If I were using this as a library I would want to know that
PssFreeSnapshot
is failing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I was going back and forth over that. changed to return error codes from GetCurrentProcess and PssFreeSnapshot