libavcodec/utils.c:314: error: Use After Free
  accessing memory that was invalidated by call to `free()` on line 313 indirectly during the call to `av_free()`.

libavcodec/utils.c:300:24: invalidation part of the trace starts here
298.     /* allocate InternalBuffer if needed */
299.     if (!avci->buffer) {
300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                            ^
301.         if (!avci->buffer)
302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:24: passed as argument to `av_mallocz`
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                              ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:24: return from call to `av_mallocz`
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                              ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:9: assigned
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
               ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:304:5: assigned
  302.             return AVERROR(ENOMEM);
  303.     }
  304.     buf = avci->buffer;
           ^
  305. 
  306.     /* if there is a previously-used internal buffer, check its size and

libavcodec/utils.c:313:17: when calling `av_free` here
  311.             av_free(buf->extended_data[0]);
  312.             if (buf->extended_data != buf->data)
  313.                 av_free(&buf->extended_data);
                       ^
  314.             buf->extended_data = NULL;
  315.             buf->data[0] = NULL;

libavutil/mem.c:137:1: parameter `ptr` of av_free
    135. }
    136. 
    137. void av_free(void *ptr)
         ^
    138. {
    139. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:143:5: was invalidated by call to `free()`
    141.         free((char*)ptr - ((char*)ptr)[-1]);
    142. #else
    143.     free(ptr);
             ^
    144. #endif
    145. }

libavcodec/utils.c:300:24: use-after-lifetime part of the trace starts here
298.     /* allocate InternalBuffer if needed */
299.     if (!avci->buffer) {
300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                            ^
301.         if (!avci->buffer)
302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:24: passed as argument to `av_mallocz`
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                              ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:24: return from call to `av_mallocz`
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
                              ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:300:9: assigned
  298.     /* allocate InternalBuffer if needed */
  299.     if (!avci->buffer) {
  300.         avci->buffer = av_mallocz(sizeof(InternalBuffer));
               ^
  301.         if (!avci->buffer)
  302.             return AVERROR(ENOMEM);

libavcodec/utils.c:304:5: assigned
  302.             return AVERROR(ENOMEM);
  303.     }
  304.     buf = avci->buffer;
           ^
  305. 
  306.     /* if there is a previously-used internal buffer, check its size and

libavcodec/utils.c:314:13: invalid access occurs here
  312.             if (buf->extended_data != buf->data)
  313.                 av_free(&buf->extended_data);
  314.             buf->extended_data = NULL;
                   ^
  315.             buf->data[0] = NULL;
  316.         }

static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
{
    AVCodecInternal *avci = avctx->internal;
    InternalBuffer *buf;
    int buf_size, ret;
    buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
                                          frame->nb_samples, avctx->sample_fmt,
                                          32);
    if (buf_size < 0)
        return AVERROR(EINVAL);
    if (!avci->buffer) {
        avci->buffer = av_mallocz(sizeof(InternalBuffer));
        if (!avci->buffer)
            return AVERROR(ENOMEM);
    }
    buf = avci->buffer;
    if (buf->extended_data) {
        if (buf->extended_data[0] && buf_size > buf->audio_data_size) {
            av_free(buf->extended_data[0]);
            if (buf->extended_data != buf->data)
                av_free(&buf->extended_data);
            buf->extended_data = NULL;
            buf->data[0] = NULL;
        }
        if (buf->nb_channels != avctx->channels) {
            if (buf->extended_data != buf->data)
                av_free(buf->extended_data);
            buf->extended_data = NULL;
        }
    }
    if (!buf->extended_data) {
        if (!buf->data[0]) {
            if (!(buf->data[0] = av_mallocz(buf_size)))
                return AVERROR(ENOMEM);
            buf->audio_data_size = buf_size;
        }
        if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
                                            avctx->sample_fmt, buf->data[0],
                                            buf->audio_data_size, 32)))
            return ret;
        if (frame->extended_data == frame->data)
            buf->extended_data = buf->data;
        else
            buf->extended_data = frame->extended_data;
        memcpy(buf->data, frame->data, sizeof(frame->data));
        buf->linesize[0] = frame->linesize[0];
        buf->nb_channels = avctx->channels;
    } else {
        frame->extended_data = buf->extended_data;
        frame->linesize[0]   = buf->linesize[0];
        memcpy(frame->data, buf->data, sizeof(frame->data));
    }
    frame->type          = FF_BUFFER_TYPE_INTERNAL;
    if (avctx->pkt) frame->pkt_pts = avctx->pkt->pts;
    else            frame->pkt_pts = AV_NOPTS_VALUE;
    frame->reordered_opaque = avctx->reordered_opaque;
    if (avctx->debug & FF_DEBUG_BUFFERS)
        av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
               "internal audio buffer used\n", frame);
    return 0;
}
['static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)\n{\n    AVCodecInternal *avci = avctx->internal;\n    InternalBuffer *buf;\n    int buf_size, ret;\n    buf_size = av_samples_get_buffer_size(NULL, avctx->channels,\n                                          frame->nb_samples, avctx->sample_fmt,\n                                          32);\n    if (buf_size < 0)\n        return AVERROR(EINVAL);\n    if (!avci->buffer) {\n        avci->buffer = av_mallocz(sizeof(InternalBuffer));\n        if (!avci->buffer)\n            return AVERROR(ENOMEM);\n    }\n    buf = avci->buffer;\n    if (buf->extended_data) {\n        if (buf->extended_data[0] && buf_size > buf->audio_data_size) {\n            av_free(buf->extended_data[0]);\n            if (buf->extended_data != buf->data)\n                av_free(&buf->extended_data);\n            buf->extended_data = NULL;\n            buf->data[0] = NULL;\n        }\n        if (buf->nb_channels != avctx->channels) {\n            if (buf->extended_data != buf->data)\n                av_free(buf->extended_data);\n            buf->extended_data = NULL;\n        }\n    }\n    if (!buf->extended_data) {\n        if (!buf->data[0]) {\n            if (!(buf->data[0] = av_mallocz(buf_size)))\n                return AVERROR(ENOMEM);\n            buf->audio_data_size = buf_size;\n        }\n        if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,\n                                            avctx->sample_fmt, buf->data[0],\n                                            buf->audio_data_size, 32)))\n            return ret;\n        if (frame->extended_data == frame->data)\n            buf->extended_data = buf->data;\n        else\n            buf->extended_data = frame->extended_data;\n        memcpy(buf->data, frame->data, sizeof(frame->data));\n        buf->linesize[0] = frame->linesize[0];\n        buf->nb_channels = avctx->channels;\n    } else {\n        frame->extended_data = buf->extended_data;\n        frame->linesize[0]   = buf->linesize[0];\n        memcpy(frame->data, buf->data, sizeof(frame->data));\n    }\n    frame->type          = FF_BUFFER_TYPE_INTERNAL;\n    if (avctx->pkt) frame->pkt_pts = avctx->pkt->pts;\n    else            frame->pkt_pts = AV_NOPTS_VALUE;\n    frame->reordered_opaque = avctx->reordered_opaque;\n    if (avctx->debug & FF_DEBUG_BUFFERS)\n        av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "\n               "internal audio buffer used\\n", frame);\n    return 0;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n    if (ptr)\n        free((char*)ptr - ((char*)ptr)[-1]);\n#else\n    free(ptr);\n#endif\n}']