-
Notifications
You must be signed in to change notification settings - Fork 0
Enumerate devices on linux #3
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
Conversation
kisielk
left a comment
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.
API looks good to me. A few comments about memory leakage.
midi_linux.go
Outdated
| if rc := C.snd_ctl_open(&ctl, name, 0); rc != 0 { | ||
| return nil, alsaMidiError(rc) | ||
| } | ||
| C.free(unsafe.Pointer(name)) |
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.
This will leak memory if rc != 0. Should probably use defer after the C.Cstring allocation.
|
|
||
| func getDeviceDevices(ctl *C.snd_ctl_t, card C.int, device C.uint) ([]*Device, error) { | ||
| var info *C.snd_rawmidi_info_t | ||
| C.snd_rawmidi_info_malloc(&info) |
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.
This probably needs to be freed somewhere?
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.
Done
midi_linux.go
Outdated
| return errors.Errorf("error opening device %d", result.error) | ||
| } | ||
| d.conn = result.midi | ||
| C.free(unsafe.Pointer(id)) |
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.
This will leak id if result.error is != 0. You should probably just use defer C.free right after the call to C.CString
|
@kisielk thanks for the review. I'll take a look at implementing the same API on mac |
Proposed API for #1