[Libva] [PATCH 3/3] check memory alloc to avoid NULL and initialize value in YUV_blend_with_pic
Lim, Siew Hoon
siew.hoon.lim at intel.com
Tue Jun 28 12:35:11 UTC 2016
Sorry.
Please ignore this patch for code review.
I will rework it and re-send again tomorrow.
...siewhoon
> -----Original Message-----
> From: Libva [mailto:libva-bounces at lists.freedesktop.org] On Behalf Of Lim
> Siew Hoon
> Sent: Monday, June 27, 2016 8:27 PM
> To: libva at lists.freedesktop.org
> Subject: [Libva] [PATCH 3/3] check memory alloc to avoid NULL and initialize
> value in YUV_blend_with_pic
>
> Signed-off-by: Lim Siew Hoon <siew.hoon.lim at intel.com>
> ---
> test/loadsurface.h | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/test/loadsurface.h b/test/loadsurface.h index a4cdb9d..6113fe0
> 100755
> --- a/test/loadsurface.h
> +++ b/test/loadsurface.h
> @@ -54,8 +54,6 @@ static int YUV_blend_with_pic(int width, int height,
>
> static int alpha_idx = 0;
> int alpha;
> - int allocated = 0;
> -
> int row, col;
>
> if (fixed_alpha == 0) {
> @@ -72,10 +70,26 @@ static int YUV_blend_with_pic(int width, int height,
>
> if (width != 640 || height != 480) { /* need to scale the pic */
> pic_y = (unsigned char *)malloc(width * height);
> + if(pic_y == NULL) {
> + printf("Failed to allocate memory for pic_y\n");
> + return -1;
> + }
> +
> pic_u = (unsigned char *)malloc(width * height/4);
> + if(pic_u == NULL) {
> + printf("Failed to allocate memory for pic_u\n");
> + return -1;
> + }
> +
> pic_v = (unsigned char *)malloc(width * height/4);
> + if(pic_v == NULL) {
> + printf("Failed to allocate memory for pic_v\n");
> + return -1;
> + }
>
> - allocated = 1;
> + memset(pic_y, 0, width * height);
> + memset(pic_u, 0, width * height /4);
> + memset(pic_v, 0, width * height /4);
>
> scale_2dimage(pic_y_old, 640, 480,
> pic_y, width, height); @@ -133,12 +147,12 @@ static int
> YUV_blend_with_pic(int width, int height,
> }
> }
>
> -
> - if (allocated) {
> - free(pic_y);
> + if(pic_y)
> + free(pic_y);
> + if(pic_u)
> free(pic_u);
> + if(pic_v)
> free(pic_v);
> - }
>
> return 0;
> }
> --
> 2.1.0
>
> _______________________________________________
> Libva mailing list
> Libva at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/libva
More information about the Libva
mailing list