[Libva] [PATCH 2/3] check memory allocation and initialize to zero value in save_recyuv
Xiang, Haihao
haihao.xiang at intel.com
Thu Jun 30 15:22:07 UTC 2016
>-----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 2/3] check memory allocation and initialize to zero
>value in save_recyuv
>
>Signed-off-by: Lim Siew Hoon <siew.hoon.lim at intel.com>
>---
> test/encode/h264encode.c | 38
>++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
>diff --git a/test/encode/h264encode.c b/test/encode/h264encode.c
>index ce96f92..d5bc3a6 100644
>--- a/test/encode/h264encode.c
>+++ b/test/encode/h264encode.c
>@@ -1940,13 +1940,51 @@ static int save_recyuv(VASurfaceID surface_id,
> if (srcyuv_fourcc == VA_FOURCC_NV12) {
> int uv_size = 2 * (frame_width/2) * (frame_height/2);
> dst_Y = malloc(2*uv_size);
>+ if(dst_Y == NULL) {
>+ printf("Failed to allocate memory for dst_Y\n");
>+ exit(1);
>+ }
>+
> dst_U = malloc(uv_size);
>+ if(dst_U == NULL) {
>+ printf("Failed to allocate memory for dst_U\n");
>+ if(dst_Y)
>+ free(dst_Y);
First dst_y is not NULL when getting here, second free(NULL) is safe, so it is not necessary check dst_y against NULL.
>+ exit(1);
>+ }
>+
>+ memset(dst_Y, 0, 2*uv_size);
>+ memset(dst_U, 0, uv_size);
> } else if (srcyuv_fourcc == VA_FOURCC_IYUV ||
> srcyuv_fourcc == VA_FOURCC_YV12) {
> int uv_size = (frame_width/2) * (frame_height/2);
> dst_Y = malloc(4*uv_size);
>+ if(dst_Y == NULL) {
>+ printf("Failed to allocate memory for dst_Y\n");
>+ exit(1);
>+ }
>+
> dst_U = malloc(uv_size);
>+ if(dst_U == NULL) {
>+ printf("Failed to allocate memory for dst_U\n");
>+ if(dst_Y)
>+ free(dst_Y);
Same as above.
>+ exit(1);
>+ }
>+
> dst_V = malloc(uv_size);
>+ if(dst_V == NULL) {
>+ printf("Failed to allocate memory for dst_V\n");
>+ if(dst_Y)
>+ free(dst_Y);
>+ if(dst_U)
>+ free(dst_U);
Same as above.
>+ exit(1);
>+ }
>+
>+ memset(dst_Y, 0, 4*uv_size);
>+ memset(dst_U, 0, uv_size);
>+ memset(dst_V, 0, uv_size);
> } else {
> printf("Unsupported source YUV format\n");
> exit(1);
>--
>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