Ticket #7084: leak_poc.c

File leak_poc.c, 2.1 KB (added by Kira, 12 months ago)

poc of memory leak

Line 
1#include <stdio.h>
2
3#include "libavfilter/avfilter.h"
4#include "libavfilter/buffersink.h"
5#include "libavfilter/buffersrc.h"
6
7
8int leak_once()
9{
10    // reference: doc/examples/filtering_video.c
11    int ret;
12
13    AVFilterContext *buffersink_ctx;
14    AVFilterContext *buffersrc_ctx;
15    AVFilterGraph *filter_graph;
16
17    avfilter_register_all();
18
19    char args[512];
20    const AVFilter *buffersrc = avfilter_get_by_name("buffer");
21    const AVFilter *buffersink = avfilter_get_by_name("buffersink");
22    AVFilterInOut *outputs = avfilter_inout_alloc();
23    AVFilterInOut *inputs = avfilter_inout_alloc();
24    enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE};
25    AVBufferSinkParams *buffersink_params;
26
27    filter_graph = avfilter_graph_alloc();
28
29    snprintf(args, sizeof(args),
30             "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
31             100, 100, AV_PIX_FMT_YUV420P,
32             1, 25, 1, 1);
33
34    ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, filter_graph);
35    if (ret < 0)
36    {
37        printf("Cannot create buffer source\n");
38        return ret;
39    }
40
41    buffersink_params = av_buffersink_params_alloc();
42    buffersink_params->pixel_fmts = pix_fmts;
43    ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, buffersink_params, filter_graph);
44    av_free(buffersink_params);
45    if (ret < 0)
46    {
47        printf("Cannot create buffer sink\n");
48        return ret;
49    }
50
51    outputs->name = av_strdup("in");
52    outputs->filter_ctx = buffersrc_ctx;
53    outputs->pad_idx = 0;
54    outputs->next = NULL;
55
56    inputs->name = av_strdup("out");
57    inputs->filter_ctx = buffersink_ctx;
58    inputs->pad_idx = 0;
59    inputs->next = NULL;
60
61    avfilter_graph_parse_ptr(filter_graph, "spectrumsynth", &inputs, &outputs, NULL);
62    avfilter_graph_config(filter_graph, NULL);
63
64    avfilter_inout_free(&inputs);
65    avfilter_inout_free(&outputs);
66    avfilter_graph_free(&filter_graph);
67    return 0;
68}
69
70int main()
71{
72    while(1)
73    {
74        // once leak 32 + 32 + 4 bytes
75        leak_once();
76    }
77}