st/omx: keep the name, (name|role)_specific strings dynamically allocated
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 26 Jun 2014 16:43:46 +0000 (17:43 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 27 Jun 2014 18:13:31 +0000 (19:13 +0100)
... as it's caller (the external program omxregister-bellagio) is the one
who frees all of the allocated memory.

Reported-by: Pedretti Fabio <pedretti.fabio@gmail.com>
Tested-by: Fabio Pedretti <pedretti.fabio@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/state_trackers/omx/vid_dec.c
src/gallium/state_trackers/omx/vid_enc.c

index 4442c5c925d38e947c97a2c09f93a62b8caa2b43..13f4f5558b1b5973c748008844aa48f637e53060 100644 (file)
@@ -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;
 }
index 15eeb091225a0a1d24238e8e8eee27b1b645ea49..871b465f281bb55bbc8c69e7f11bae0a2374766f 100644 (file)
@@ -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;
 }