Commit 769fab2a authored by Jesper Juhl's avatar Jesper Juhl Committed by Takashi Iwai

ALSA: Fix memory leak on error in snd_compr_set_params()

If copy_from_user() does not return 0 we'll leak the memory we
allocated for 'params' when that variable goes out of scope.

Also a small CodingStyle cleanup: Use braces on both branches of
if/else when one branch needs it.
Signed-off-by: default avatarJesper Juhl <jj@chaosbits.net>
Acked-by: default avatarVinod Koul <vinod.koul@linux.intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4d20bb1d
...@@ -441,19 +441,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) ...@@ -441,19 +441,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
params = kmalloc(sizeof(*params), GFP_KERNEL); params = kmalloc(sizeof(*params), GFP_KERNEL);
if (!params) if (!params)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(params, (void __user *)arg, sizeof(*params))) if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
return -EFAULT; retval = -EFAULT;
goto out;
}
retval = snd_compr_allocate_buffer(stream, params); retval = snd_compr_allocate_buffer(stream, params);
if (retval) { if (retval) {
kfree(params); retval = -ENOMEM;
return -ENOMEM; goto out;
} }
retval = stream->ops->set_params(stream, params); retval = stream->ops->set_params(stream, params);
if (retval) if (retval)
goto out; goto out;
stream->runtime->state = SNDRV_PCM_STATE_SETUP; stream->runtime->state = SNDRV_PCM_STATE_SETUP;
} else } else {
return -EPERM; return -EPERM;
}
out: out:
kfree(params); kfree(params);
return retval; return retval;
......
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