Fix memory leak for saved channel list
authorIan Abbott <abbotti@mev.co.uk>
Fri, 28 Sep 2012 12:06:54 +0000 (13:06 +0100)
committerIan Abbott <abbotti@mev.co.uk>
Fri, 28 Sep 2012 12:06:54 +0000 (13:06 +0100)
commit62149c2a160abe17fa1fa4cb4af65a12171f3163
treebafed9eec200f3617b50fe02ed7b16a06c67dec7
parentc605a5501ead027e529b0ea86e0bb7688185e7f4
Fix memory leak for saved channel list

When `do_cmd_ioctl()` allocates memory for the kernel copy of a channel
list, it frees any previously allocated channel list in
`async->cmd.chanlist` and replaces it with the new one.  However, if the
device is ever removed (or "detached") the cleanup code in
`cleanup_device()` in "drivers.c" does not free this memory so it is
lost.

A sensible place to free the kernel copy of the channel list is in
`do_become_nonbusy()` as at that point the comedi asynchronous command
associated with the channel list is no longer valid.  Free the channel
list in `do_become_nonbusy()` instead of `do_cmd_ioctl()` and clear the
pointer to prevent it being freed more than once.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
comedi/comedi_fops.c