From a6ca69ef01c2708cf41894a48e3452ab6e748732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Mart=C3=ADn=20Oya?= Date: Wed, 13 Apr 2022 11:24:24 +0200 Subject: [PATCH] Fix: double memory free at formatContextFinalizer (format.cc) --- src/format.cc | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/format.cc b/src/format.cc index 1bfd7e7..c572cc7 100644 --- a/src/format.cc +++ b/src/format.cc @@ -3837,37 +3837,34 @@ void formatContextFinalizer(napi_env env, void* data, void* hint) { if (fmtRef->fmtCtx != nullptr) { fc = fmtRef->fmtCtx; if (fc->pb != nullptr) { - if (adaptor) - avio_context_free(&fc->pb); - else { + if (adaptor) { + avformat_free_context(fc); + } else { ret = avio_closep(&fc->pb); if (ret < 0) { printf("DEBUG: For url '%s', %s", (fc->url != nullptr) ? fc->url : "unknown", avErrorMsg("error closing IO: ", ret)); } - } - } - if (fc->iformat != nullptr) { - avformat_close_input(&fc); - } else { - // FIXME this is segfaulting ... why - /* if (fc->codec_whitelist != nullptr) { - av_freep(fc->codec_whitelist); - } - if (fc->format_whitelist != nullptr) { - av_freep(fc->format_whitelist); - } - if (fc->protocol_whitelist != nullptr) { - av_freep(fc->protocol_whitelist); + if (fc->iformat != nullptr) { + avformat_close_input(&fc); + } else { + // FIXME this is segfaulting ... why + /* if (fc->codec_whitelist != nullptr) { + av_freep(fc->codec_whitelist); + } + if (fc->format_whitelist != nullptr) { + av_freep(fc->format_whitelist); + } + if (fc->protocol_whitelist != nullptr) { + av_freep(fc->protocol_whitelist); + } + if (fc->protocol_blacklist != nullptr) { + av_freep(fc->protocol_blacklist); + } */ + } } - if (fc->protocol_blacklist != nullptr) { - av_freep(fc->protocol_blacklist); - } */ } - - if (adaptor != nullptr) // crashes otherwise... - avformat_free_context(fc); } delete fmtRef;