Skip to content

Commit

Permalink
Apply PR. Fix: double memory free at formatContextFinalizer (format.cc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Garbowski committed Jun 22, 2022
1 parent fc3ae39 commit 396c001
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 396c001

Please sign in to comment.