avformat_close_input memory leak?

Viewed 343

I developed an app to push live stream with ffmpeg. When I checked the app with leaks --atExit -- <the app> (I'm on mac), I found some memory leak with AVFormatContext.

The minimized code are provided below:

#include <iostream>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
}

void foo() {
    avdevice_register_all();

    AVFormatContext *avInputFormatContext = avformat_alloc_context();
    AVInputFormat *avInputFormat = av_find_input_format("avfoundation");
    std::cout << "open input" << std::endl;
    int ret = avformat_open_input(&avInputFormatContext, "Capture screen 0", avInputFormat, nullptr);
    if (ret < 0) { std::cout << "open input failed: " << ret << std::endl; return;}

    avformat_close_input(&avInputFormatContext);

}

int main() {
    foo();
    return 0;
}

The output is

Process:         ffmpegtest [87726]
Path:            /Users/USER/*/ffmpegtest
Load Address:    0x10a752000
Identifier:      ffmpegtest
Version:         ???
Code Type:       X86-64
Platform:        macOS
Parent Process:  leaks [87725]

Date/Time:       2021-01-20 15:44:57.533 +0800
Launch Time:     2021-01-20 15:44:55.760 +0800
OS Version:      macOS 11.1 (20C69)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version:  Xcode 12.3 (12C33)

Physical footprint:         9.9M
Physical footprint (peak):  10.6M
----

leaks Report Version: 4.0
Process 87726: 14143 nodes malloced for 2638 KB
Process 87726: 1 leak for 32 total leaked bytes.

    1 (32 bytes) ROOT LEAK: 0x7f8c61e1b040 [32]  length: 16  "Capture screen 0"

Did I miss something?

0 Answers
Related