Since kstrdup() allocate a space for e->name and will not automatically
free.
If kzalloc() fails, we just kfree e without e->name.
Then we cannot get the pointer 'e->name' and cause the memory leak.
Fixes: 3d1387b3b8f6 ("media: vidtv: fix some warnings")
Reported-by: Hans Verkuil <[email protected]>
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/media/test-drivers/vidtv/vidtv_s302m.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
index ddaff46c440f..433fc0c7fdfa 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
@@ -474,6 +474,7 @@ struct vidtv_encoder
ctx = kzalloc(priv_sz, GFP_KERNEL);
if (!ctx) {
+ kfree(e->name);
kfree(e);
return NULL;
}
--
2.25.1
On 12/01/2022 03:05, Jiasheng Jiang wrote:
> Since kstrdup() allocate a space for e->name and will not automatically
> free.
> If kzalloc() fails, we just kfree e without e->name.
> Then we cannot get the pointer 'e->name' and cause the memory leak.
>
> Fixes: 3d1387b3b8f6 ("media: vidtv: fix some warnings")
> Reported-by: Hans Verkuil <[email protected]>
> Signed-off-by: Jiasheng Jiang <[email protected]>
> ---
> drivers/media/test-drivers/vidtv/vidtv_s302m.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
> index ddaff46c440f..433fc0c7fdfa 100644
> --- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c
> +++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
> @@ -474,6 +474,7 @@ struct vidtv_encoder
>
> ctx = kzalloc(priv_sz, GFP_KERNEL);
> if (!ctx) {
> + kfree(e->name);
It should also free e->encoder_buf.
Regards,
Hans
> kfree(e);
> return NULL;
> }