Skip to content

Commit

Permalink
sound: fix a memory leak bug
Browse files Browse the repository at this point in the history
In sound_insert_unit(), the controlling structure 's' is allocated through
kmalloc(). Then it is added to the sound driver list by invoking
__sound_insert_unit(). Later on, if __register_chrdev() fails, 's' is
removed from the list through __sound_remove_unit(). If 'index' is not less
than 0, -EBUSY is returned to indicate the error. However, 's' is not
deallocated on this execution path, leading to a memory leak bug.

To fix the above issue, free 's' before -EBUSY is returned.

Signed-off-by: Wenwen Wang <[email protected]>
Cc: <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
wenwenwang1 authored and tiwai committed Aug 8, 2019
1 parent c02f77d commit c7cd7c7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sound/sound_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
goto retry;
}
spin_unlock(&sound_loader_lock);
return -EBUSY;
r = -EBUSY;
goto fail;
}
}

Expand Down

0 comments on commit c7cd7c7

Please sign in to comment.