Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1519618 > unrolled thread

[PATCH] Staging: media: davinci_vpfe: - Fix for memory leak if

Started byShailendra Verma <shailendra.v@samsung.com>
First post2016-11-11 10:00 +0100
Last post2016-11-22 23:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Staging: media: davinci_vpfe: - Fix for memory leak if Shailendra Verma <shailendra.v@samsung.com> - 2016-11-11 10:00 +0100
    Re: [PATCH] Staging: media: davinci_vpfe: - Fix for memory leak if Laurent Pinchart <laurent.pinchart@ideasonboard.com> - 2016-11-22 23:00 +0100

#1519618 — [PATCH] Staging: media: davinci_vpfe: - Fix for memory leak if

FromShailendra Verma <shailendra.v@samsung.com>
Date2016-11-11 10:00 +0100
Subject[PATCH] Staging: media: davinci_vpfe: - Fix for memory leak if
Message-ID<sCfQJ-22L-5@gated-at.bofh.it>
From: "Shailendra Verma" <shailendra.v@samsung.com>

Fix to avoid possible memory leak if the decoder initialization
got failed.Free the allocated memory for file handle object
before return in case decoder initialization fails.

Signed-off-by: Shailendra Verma <shailendra.capricorn@gmail.com>
---
 drivers/staging/media/davinci_vpfe/vpfe_video.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 8be9f85..80c2e25 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -423,6 +423,7 @@ static int vpfe_open(struct file *file)
 	/* If decoder is not initialized. initialize it */
 	if (!video->initialized && vpfe_update_pipe_state(video)) {
 		mutex_unlock(&video->lock);
+		kfree(handle);
 		return -ENODEV;
 	}
 	/* Increment device users counter */
-- 
1.7.9.5

[toc] | [next] | [standalone]


#1527966

FromLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Date2016-11-22 23:00 +0100
Message-ID<sGrgB-4lS-15@gated-at.bofh.it>
In reply to#1519618
Hi Shailendra,

Thank you for the patch.

I think the subject line is incomplete.

On Friday 11 Nov 2016 14:21:41 Shailendra Verma wrote:
> From: "Shailendra Verma" <shailendra.v@samsung.com>
> 
> Fix to avoid possible memory leak if the decoder initialization
> got failed.Free the allocated memory for file handle object
> before return in case decoder initialization fails.
> 
> Signed-off-by: Shailendra Verma <shailendra.capricorn@gmail.com>
> ---
>  drivers/staging/media/davinci_vpfe/vpfe_video.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> b/drivers/staging/media/davinci_vpfe/vpfe_video.c index 8be9f85..80c2e25
> 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -423,6 +423,7 @@ static int vpfe_open(struct file *file)

(Adding a bit of context here for review purpose)

        v4l2_fh_init(&handle->vfh, &video->video_dev);
        v4l2_fh_add(&handle->vfh);

        mutex_lock(&video->lock)

>  	/* If decoder is not initialized. initialize it */
>  	if (!video->initialized && vpfe_update_pipe_state(video)) {
>  		mutex_unlock(&video->lock);
> +		kfree(handle);

This isn't enough. The v4l2_fh_init() and v4l2_fh_add() calls have side 
effects. The major one is adding vfh to the file handles' list in video_dev. 
If you just free the memory here you will get a crash pretty soon afterwards.

>  		return -ENODEV;
>  	}
>  	/* Increment device users counter */

-- 
Regards,

Laurent Pinchart

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web