[Libva] [PATCH V1][libva] fix check NULL issues reported by Klockwork

Xiang, Haihao haihao.xiang at intel.com
Thu May 26 04:17:47 UTC 2016


On Mon, 2016-05-23 at 13:46 +0800, peng.chen wrote:
> Signed-off-by: peng.chen <peng.c.chen at intel.com>
> ---
>  va/va_trace.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/va/va_trace.c b/va/va_trace.c
> index 994422e..398ca1a 100644
> --- a/va/va_trace.c
> +++ b/va/va_trace.c
> @@ -501,7 +501,10 @@ static void FILE_NAME_SUFFIX(
>      int tmp = strnlen(env_value, max_size);
>      int left = max_size - tmp;
>      struct timeval tv;
> -    int size = strlen(suffix_str);
> +    int size = 0;
> +    
> +    if(suffix_str)
> +        strlen(suffix_str);
>  
>      if(left < (size + 8 + 10))
>          return;
> @@ -735,8 +738,14 @@ void va_TraceInit(VADisplay dpy)
>      struct va_trace *pva_trace = calloc(sizeof(struct va_trace), 1);
>      struct trace_context *trace_ctx = calloc(sizeof(struct
> trace_context), 1);
>  
> -    if (pva_trace == NULL || trace_ctx == NULL)
> +    if (pva_trace == NULL || trace_ctx == NULL) {
> +        if(pva_trace)
> +            free(pva_trace);
> +
> +        if(trace_ctx)
> +            free(trace_ctx);

Don't need to check the pointer against NULL because free() does
nothing with a NULL pointer.


>          return;
> +    }
>  
>      if (va_parseConfig("LIBVA_TRACE", &env_value[0]) == 0) {
>          pva_trace->fn_log_env = strdup(env_value);
> @@ -1474,6 +1483,9 @@ void va_TraceCreateBuffer (
>      VABufferID *buf_id		/* out */
>  )
>  {
> +    if(!buf_id)
> +        return;
> +
>      DPY2TRACECTX(dpy, context, VA_INVALID_ID);
>  
>      add_trace_buf_info(pva_trace, context, *buf_id);


More information about the Libva mailing list