C++ avformat\u close\u输入内存泄漏?

C++ avformat\u close\u输入内存泄漏?,c++,ffmpeg,memory-leaks,C++,Ffmpeg,Memory Leaks,我开发了一个应用程序,用ffmpeg推送实时流。当我用泄漏--atExit--(我在mac上)检查应用程序时,我发现一些AVFormatContext内存泄漏 最小化代码如下所示: #include <iostream> extern "C" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavdevice/avdevi

我开发了一个应用程序,用ffmpeg推送实时流。当我用
泄漏--atExit--
(我在mac上)检查应用程序时,我发现一些AVFormatContext内存泄漏

最小化代码如下所示:

#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;
}


我错过了什么吗?

可能只是一些静态分配,在循环中运行代码两次,看看是否有两个“泄漏”avformat\u free\u上下文(avInputFormatContext)@AlanBirtles是的。如果我运行两次,我会得到两个“泄漏”。@StarShine上面的代码显示avformat\u close\u输入将调用avformat\u free\u上下文。但我会试试。@StarShine结果不会改变。
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"