提交 769fab2a 编写于 作者: J Jesper Juhl 提交者: 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: NJesper Juhl <jj@chaosbits.net>
Acked-by: NVinod Koul <vinod.koul@linux.intel.com>
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 4d20bb1d
......@@ -441,19 +441,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
params = kmalloc(sizeof(*params), GFP_KERNEL);
if (!params)
return -ENOMEM;
if (copy_from_user(params, (void __user *)arg, sizeof(*params)))
return -EFAULT;
if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
retval = -EFAULT;
goto out;
}
retval = snd_compr_allocate_buffer(stream, params);
if (retval) {
kfree(params);
return -ENOMEM;
retval = -ENOMEM;
goto out;
}
retval = stream->ops->set_params(stream, params);
if (retval)
goto out;
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
} else
} else {
return -EPERM;
}
out:
kfree(params);
return retval;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册