[Libva] [PATCH 3/3] check memory alloc to avoid NULL and initialize value in YUV_blend_with_pic

Xiang, Haihao haihao.xiang at intel.com
Thu Jun 30 16:04:10 UTC 2016


Sorry, I didn't see your replying to this patch. Please ignore my comments if you fix the errors in your new patch.

Thanks
Haihao

>-----Original Message-----
>From: Libva [mailto:libva-bounces at lists.freedesktop.org] On Behalf Of Xiang,
>Haihao
>Sent: Thursday, June 30, 2016 11:55 PM
>To: Lim, Siew Hoon <siew.hoon.lim at intel.com>; libva at lists.freedesktop.org
>Subject: Re: [Libva] [PATCH 3/3] check memory alloc to avoid NULL and
>initialize value in YUV_blend_with_pic
>
>
>
>>-----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_y isn't freed before return
>
>>+        }
>>+
>>         pic_v = (unsigned char *)malloc(width * height/4);
>>+        if(pic_v == NULL) {
>>+           printf("Failed to allocate memory for pic_v\n");
>>+           return -1;
>
>pic_y and pic_u aren't freed before return
>
>>+        }
>>
>>-        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) {
>
>It is needed to check if the memory is allocated in this function, otherwise it
>will result in error if (pic_y ==  pic_y_old, pic_u == pic_u_old and pic_v ==
>pic_v_old)
>
>>-        free(pic_y);
>>+    if(pic_y)
>>+       free(pic_y);
>>+    if(pic_u)
>>         free(pic_u);
>>+    if(pic_v)
>>         free(pic_v);
>
>
>free(NULL) is safe.
>
>>-    }
>>
>>     return 0;
>> }
>>--
>>2.1.0
>>
>>_______________________________________________
>>Libva mailing list
>>Libva at lists.freedesktop.org
>>https://lists.freedesktop.org/mailman/listinfo/libva
>_______________________________________________
>Libva mailing list
>Libva at lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/libva


More information about the Libva mailing list