[FFmpeg-devel] [PATCH] Check malloc values in swscale.

Reimar Döffinger Reimar.Doeffinger
Sat Aug 15 10:39:21 CEST 2009


On Fri, Aug 14, 2009 at 11:34:12PM -0300, Ramiro Polla wrote:
> @@ -3331,6 +3390,12 @@ SwsVector *sws_getGaussianVec(double variance, double quality){
>      double middle= (length-1)*0.5;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3350,6 +3415,12 @@ SwsVector *sws_getConstVec(double c, int length){
>      double *coeff= av_malloc(length*sizeof(double));
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3391,6 +3462,12 @@ static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){
>      int i, j;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3413,6 +3490,12 @@ static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b){
>      int i;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3430,6 +3513,12 @@ static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){
>      int i;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3448,6 +3537,12 @@ static SwsVector *sws_getShiftedVec(SwsVector *a, int shift){
>      int i;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= length;
>  
> @@ -3498,6 +3593,12 @@ SwsVector *sws_cloneVec(SwsVector *a){
>      int i;
>      SwsVector *vec= av_malloc(sizeof(SwsVector));
>  
> +    if (!coeff || !vec) {
> +        av_free(coeff);
> +        av_free(vec);
> +        return NULL;
> +    }
> +
>      vec->coeff= coeff;
>      vec->length= a->length;

I think it makes more sense to first reduce the code duplication by fatoring this out into e.g. sws_allocVec



More information about the ffmpeg-devel mailing list