Revision 0699dbb8 libavfilter/avfilter.c

View differences:

libavfilter/avfilter.c
583 583
        return AVERROR(EINVAL);
584 584

  
585 585
    ret = av_mallocz(sizeof(AVFilterContext));
586
    if (!ret)
587
        return AVERROR(ENOMEM);
586 588

  
587 589
    ret->av_class = &avfilter_class;
588 590
    ret->filter   = filter;
589 591
    ret->name     = inst_name ? av_strdup(inst_name) : NULL;
590
    if (filter->priv_size)
592
    if (filter->priv_size) {
591 593
        ret->priv     = av_mallocz(filter->priv_size);
594
        if (!ret->priv)
595
            goto err;
596
    }
592 597

  
593 598
    ret->input_count  = pad_count(filter->inputs);
594 599
    if (ret->input_count) {
595 600
        ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
601
        if (!ret->input_pads)
602
            goto err;
596 603
        memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
597 604
        ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
605
        if (!ret->inputs)
606
            goto err;
598 607
    }
599 608

  
600 609
    ret->output_count = pad_count(filter->outputs);
601 610
    if (ret->output_count) {
602 611
        ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
612
        if (!ret->output_pads)
613
            goto err;
603 614
        memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
604 615
        ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
616
        if (!ret->outputs)
617
            goto err;
605 618
    }
606 619

  
607 620
    *filter_ctx = ret;
608 621
    return 0;
622

  
623
err:
624
    av_freep(&ret->inputs);
625
    av_freep(&ret->input_pads);
626
    ret->input_count = 0;
627
    av_freep(&ret->outputs);
628
    av_freep(&ret->output_pads);
629
    ret->output_count = 0;
630
    av_freep(&ret->priv);
631
    av_free(ret);
632
    return AVERROR(ENOMEM);
609 633
}
610 634

  
611 635
void avfilter_free(AVFilterContext *filter)

Also available in: Unified diff