[Mesa-dev] [PATCH] st/omx: keep the name, (name|role)_specific strings dynamically allocated
Christian König
deathsimple at vodafone.de
Fri Jun 27 01:21:14 PDT 2014
Am 26.06.2014 18:45, schrieb Emil Velikov:
> ... as it's caller (the external program omxregister-bellagio) is the one
> who frees all of the allocated memory.
>
> Cc: Pedretti Fabio <pedretti.fabio at gmail.com>
> Reported-by: Pedretti Fabio <pedretti.fabio at gmail.com>
> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
Reviewed-by: Christian König <christian.koenig at amd.com>
> ---
> src/gallium/state_trackers/omx/vid_dec.c | 41 ++++++++++++++++++++++++++------
> src/gallium/state_trackers/omx/vid_enc.c | 20 ++++++++++++++--
> 2 files changed, 52 insertions(+), 9 deletions(-)
>
> diff --git a/src/gallium/state_trackers/omx/vid_dec.c b/src/gallium/state_trackers/omx/vid_dec.c
> index 4442c5c..13f4f55 100644
> --- a/src/gallium/state_trackers/omx/vid_dec.c
> +++ b/src/gallium/state_trackers/omx/vid_dec.c
> @@ -72,6 +72,10 @@ OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
> comp->componentVersion.s.nStep = 1;
> comp->name_specific_length = 2;
>
> + comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->name == NULL)
> + goto error;
> +
> comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *));
> if (comp->name_specific == NULL)
> goto error;
> @@ -80,21 +84,44 @@ OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
> if (comp->role_specific == NULL)
> goto error;
>
> - comp->name = OMX_VID_DEC_BASE_NAME;
> - comp->name_specific[0] = OMX_VID_DEC_MPEG2_NAME;
> - comp->name_specific[1] = OMX_VID_DEC_AVC_NAME;
> + comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->name_specific[0] == NULL)
> + goto error_specific;
> +
> + comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->name_specific[1] == NULL)
> + goto error_specific;
> +
> + comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->role_specific[0] == NULL)
> + goto error_specific;
> +
> + comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->role_specific[1] == NULL)
> + goto error_specific;
> +
> + strcpy(comp->name, OMX_VID_DEC_BASE_NAME);
> + strcpy(comp->name_specific[0], OMX_VID_DEC_MPEG2_NAME);
> + strcpy(comp->name_specific[1], OMX_VID_DEC_AVC_NAME);
>
> - comp->role_specific[0] = OMX_VID_DEC_MPEG2_ROLE;
> - comp->role_specific[1] = OMX_VID_DEC_AVC_ROLE;
> + strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE);
> + strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE);
>
> comp->constructor = vid_dec_Constructor;
>
> return OMX_ErrorNone;
>
> -error:
> +error_specific:
> + FREE(comp->role_specific[1]);
> + FREE(comp->role_specific[0]);
> + FREE(comp->name_specific[1]);
> + FREE(comp->name_specific[0]);
>
> - FREE(comp->name_specific);
> +error:
> FREE(comp->role_specific);
> + FREE(comp->name_specific);
> +
> + FREE(comp->name);
>
> return OMX_ErrorInsufficientResources;
> }
> diff --git a/src/gallium/state_trackers/omx/vid_enc.c b/src/gallium/state_trackers/omx/vid_enc.c
> index 15eeb09..871b465 100644
> --- a/src/gallium/state_trackers/omx/vid_enc.c
> +++ b/src/gallium/state_trackers/omx/vid_enc.c
> @@ -105,7 +105,9 @@ OMX_ERRORTYPE vid_enc_LoaderComponent(stLoaderComponentType *comp)
> comp->name_specific_length = 1;
> comp->constructor = vid_enc_Constructor;
>
> - comp->name = OMX_VID_ENC_BASE_NAME;
> + comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (!comp->name)
> + return OMX_ErrorInsufficientResources;
>
> comp->name_specific = CALLOC(1, sizeof(char *));
> if (!comp->name_specific)
> @@ -115,16 +117,30 @@ OMX_ERRORTYPE vid_enc_LoaderComponent(stLoaderComponentType *comp)
> if (!comp->role_specific)
> goto error_arrays;
>
> - comp->name_specific[0] = OMX_VID_ENC_AVC_NAME;
> + comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->name_specific[0] == NULL)
> + goto error_specific;
> +
> + comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
> + if (comp->role_specific[0] == NULL)
> + goto error_specific;
>
> + comp->name = OMX_VID_ENC_BASE_NAME;
> + comp->name_specific[0] = OMX_VID_ENC_AVC_NAME;
> comp->role_specific[0] = OMX_VID_ENC_AVC_ROLE;
>
> return OMX_ErrorNone;
>
> +error_specific:
> + FREE(comp->role_specific[0]);
> + FREE(comp->name_specific[0]);
> +
> error_arrays:
> FREE(comp->role_specific);
> FREE(comp->name_specific);
>
> + FREE(comp->name);
> +
> return OMX_ErrorInsufficientResources;
> }
>
More information about the mesa-dev
mailing list