diff options
author | Lim Siew Hoon <siew.hoon.lim@intel.com> | 2016-07-01 10:30:21 +0800 |
---|---|---|
committer | Xiang, Haihao <haihao.xiang@intel.com> | 2016-08-22 13:04:29 +0800 |
commit | 1aa71317e9d904ed630714388986f316d9fc2567 (patch) | |
tree | 730716447a660f639d42dc32953473327b8c628e | |
parent | b5221fc19e464cf0ad59d47137ad3d73948e3d5b (diff) | |
download | libva-1aa71317e9d904ed630714388986f316d9fc2567.tar.gz |
check memory alloc to avoid NULL and initialize value in YUV_blend_with_pic (v2)
v2:
Add in second free(NULL) for pic_y and third free(NULL) for pic_u.
Put back 'allocated' missing consider about the pic_y, pic_u and pic_v
will be contains pic_y_old, pic_u_old and pic_v_old will be assign to
pic_y, pic_u and pic_v.
Signed-off-by: Lim Siew Hoon <siew.hoon.lim@intel.com>
(cherry picked from commit 1c2997307e007c9a999b33da9c237dda370d1990)
-rwxr-xr-x | test/loadsurface.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/test/loadsurface.h b/test/loadsurface.h index a4cdb9d..4d7be98 100755 --- a/test/loadsurface.h +++ b/test/loadsurface.h @@ -72,10 +72,30 @@ 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); - pic_v = (unsigned char *)malloc(width * height/4); + if(pic_u == NULL) { + printf("Failed to allocate memory for pic_u\n"); + free(pic_y); + return -1; + } + pic_v = (unsigned char *)malloc(width * height/4); + if(pic_v == NULL) { + printf("Failed to allocate memory for pic_v\n"); + free(pic_y); + free(pic_u); + 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,7 +153,6 @@ static int YUV_blend_with_pic(int width, int height, } } - if (allocated) { free(pic_y); free(pic_u); |