diff mbox

[FFmpeg-devel] omx: Fix OOM check

Message ID 20161205174906.9611-1-timothygu99@gmail.com
State Accepted
Commit d3da8a0035734529c4e26696c9a0c6cb56633838
Headers show

Commit Message

Timothy Gu Dec. 5, 2016, 5:49 p.m. UTC
Also use av_mallocz_array().

Fixes CID1396839.
---
 libavcodec/omx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Cadhalpun Dec. 5, 2016, 8:55 p.m. UTC | #1
On 05.12.2016 18:49, Timothy Gu wrote:
> Also use av_mallocz_array().
> 
> Fixes CID1396839.
> ---
>  libavcodec/omx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/omx.c b/libavcodec/omx.c
> index c1b6fb9..b5093f4 100644
> --- a/libavcodec/omx.c
> +++ b/libavcodec/omx.c
> @@ -352,12 +352,12 @@ static av_cold int find_component(OMXContext *omx_context, void *logctx,
>          av_log(logctx, AV_LOG_WARNING, "No component for role %s found\n", role);
>          return AVERROR_ENCODER_NOT_FOUND;
>      }
> -    components = av_mallocz(sizeof(char*) * num);
> +    components = av_mallocz_array(num, sizeof(*components));

This is not really related, but probably OK.

>      if (!components)
>          return AVERROR(ENOMEM);
>      for (i = 0; i < num; i++) {
>          components[i] = av_mallocz(OMX_MAX_STRINGNAME_SIZE);
> -        if (!components) {
> +        if (!components[i]) {
>              ret = AVERROR(ENOMEM);
>              goto end;
>          }
> 

This looks good.

Best regards,
Andreas
diff mbox

Patch

diff --git a/libavcodec/omx.c b/libavcodec/omx.c
index c1b6fb9..b5093f4 100644
--- a/libavcodec/omx.c
+++ b/libavcodec/omx.c
@@ -352,12 +352,12 @@  static av_cold int find_component(OMXContext *omx_context, void *logctx,
         av_log(logctx, AV_LOG_WARNING, "No component for role %s found\n", role);
         return AVERROR_ENCODER_NOT_FOUND;
     }
-    components = av_mallocz(sizeof(char*) * num);
+    components = av_mallocz_array(num, sizeof(*components));
     if (!components)
         return AVERROR(ENOMEM);
     for (i = 0; i < num; i++) {
         components[i] = av_mallocz(OMX_MAX_STRINGNAME_SIZE);
-        if (!components) {
+        if (!components[i]) {
             ret = AVERROR(ENOMEM);
             goto end;
         }