-
Notifications
You must be signed in to change notification settings - Fork 135
Fix memory leaks in fakelibusb_test.go #139
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -566,3 +566,19 @@ | |
| func newDevHandlePointer() *libusbDevHandle { | ||
| return (*libusbDevHandle)(unsafe.Pointer(C.malloc(1))) | ||
| } | ||
|
|
||
| func freeDevicePointer(d *libusbDevice) { | ||
|
Collaborator
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. I think this should go into the test code, we don't touch these pointers directly in non-test code. Also add a block comment why these helpers are needed, something along the lines of "in tests, the code allocates some C pointers directly, it needs to be able to free them directly too". |
||
| C.free(unsafe.Pointer(d)) | ||
|
Check failure on line 571 in libusb.go
|
||
| } | ||
|
|
||
| func freeFakeTransferPointer(t *libusbTransfer) { | ||
| C.free(unsafe.Pointer(t)) | ||
| } | ||
|
|
||
| func freeContextPointer(c *libusbContext) { | ||
| C.free(unsafe.Pointer(c)) | ||
| } | ||
|
|
||
| func freeDevHandlePointer(h *libusbDevHandle) { | ||
| C.free(unsafe.Pointer(h)) | ||
| } | ||
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.
it seems like the handling of "handles" should be similar to the transfers - they should not be freed silently, but rather should be reported as a missing close on the handle?