Commit a3bdcdd0 authored by Su Hui's avatar Su Hui Committed by Jiri Kosina

HID: hidraw: fix a problem of memory leak in hidraw_release()

'struct hidraw_list' is a circular queue whose head can be smaller than
tail. Using 'list->tail != list->head' to release all memory that should
be released.

Fixes: a5623a20 ("HID: hidraw: fix memory leak in hidraw_release()")
Signed-off-by: default avatarSu Hui <suhui@nfschina.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.com>
parent 26dd6a56
...@@ -357,8 +357,11 @@ static int hidraw_release(struct inode * inode, struct file * file) ...@@ -357,8 +357,11 @@ static int hidraw_release(struct inode * inode, struct file * file)
down_write(&minors_rwsem); down_write(&minors_rwsem);
spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags); spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
for (int i = list->tail; i < list->head; i++) while (list->tail != list->head) {
kfree(list->buffer[i].value); kfree(list->buffer[list->tail].value);
list->buffer[list->tail].value = NULL;
list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
}
list_del(&list->node); list_del(&list->node);
spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags); spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
kfree(list); kfree(list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment