Skip to content

Commit 396c001

Browse files
author
Mateusz Garbowski
committed
Apply PR. Fix: double memory free at formatContextFinalizer (format.cc)
Streampunk#94
1 parent fc3ae39 commit 396c001

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/format.cc

+20-23
Original file line numberDiff line numberDiff line change
@@ -3837,37 +3837,34 @@ void formatContextFinalizer(napi_env env, void* data, void* hint) {
38373837
if (fmtRef->fmtCtx != nullptr) {
38383838
fc = fmtRef->fmtCtx;
38393839
if (fc->pb != nullptr) {
3840-
if (adaptor)
3841-
avio_context_free(&fc->pb);
3842-
else {
3840+
if (adaptor) {
3841+
avformat_free_context(fc);
3842+
} else {
38433843
ret = avio_closep(&fc->pb);
38443844
if (ret < 0) {
38453845
printf("DEBUG: For url '%s', %s", (fc->url != nullptr) ? fc->url : "unknown",
38463846
avErrorMsg("error closing IO: ", ret));
38473847
}
3848-
}
3849-
}
38503848

3851-
if (fc->iformat != nullptr) {
3852-
avformat_close_input(&fc);
3853-
} else {
3854-
// FIXME this is segfaulting ... why
3855-
/* if (fc->codec_whitelist != nullptr) {
3856-
av_freep(fc->codec_whitelist);
3857-
}
3858-
if (fc->format_whitelist != nullptr) {
3859-
av_freep(fc->format_whitelist);
3860-
}
3861-
if (fc->protocol_whitelist != nullptr) {
3862-
av_freep(fc->protocol_whitelist);
3849+
if (fc->iformat != nullptr) {
3850+
avformat_close_input(&fc);
3851+
} else {
3852+
// FIXME this is segfaulting ... why
3853+
/* if (fc->codec_whitelist != nullptr) {
3854+
av_freep(fc->codec_whitelist);
3855+
}
3856+
if (fc->format_whitelist != nullptr) {
3857+
av_freep(fc->format_whitelist);
3858+
}
3859+
if (fc->protocol_whitelist != nullptr) {
3860+
av_freep(fc->protocol_whitelist);
3861+
}
3862+
if (fc->protocol_blacklist != nullptr) {
3863+
av_freep(fc->protocol_blacklist);
3864+
} */
3865+
}
38633866
}
3864-
if (fc->protocol_blacklist != nullptr) {
3865-
av_freep(fc->protocol_blacklist);
3866-
} */
38673867
}
3868-
3869-
if (adaptor != nullptr) // crashes otherwise...
3870-
avformat_free_context(fc);
38713868
}
38723869

38733870
delete fmtRef;

0 commit comments

Comments
 (0)