@@ -3826,38 +3826,41 @@ void formatContextFinalizer(napi_env env, void* data, void* hint) {
38263826 AVFormatContext* fc = (AVFormatContext*) data;
38273827 Adaptor *adaptor = (Adaptor *)hint;
38283828 int ret;
3829- if (fc->pb != nullptr ) {
3830- if (adaptor)
3831- avio_context_free (&fc->pb );
3832- else {
3833- ret = avio_closep (&fc->pb );
3834- if (ret < 0 ) {
3835- printf (" DEBUG: For url '%s', %s" , (fc->url != nullptr ) ? fc->url : " unknown" ,
3836- avErrorMsg (" error closing IO: " , ret));
3837- }
3838- }
3839- }
3840- // FIXME this is segfaulting ... why
3841- /* if (fc->codec_whitelist != nullptr) {
3842- av_freep(fc->codec_whitelist);
3843- }
3844- if (fc->format_whitelist != nullptr) {
3845- av_freep(fc->format_whitelist);
3846- }
3847- if (fc->protocol_whitelist != nullptr) {
3848- av_freep(fc->protocol_whitelist);
3849- }
3850- if (fc->protocol_blacklist != nullptr) {
3851- av_freep(fc->protocol_blacklist);
3852- } */
3829+
38533830 if (fc->iformat != nullptr ) {
3854- // The format context we get here is copy so the close_input call won't clear the JS format context
3831+ // The format context we get here is a copy so the close_input call won't clear the JS format context
38553832 // Hence copy the formatContext pointer to null the iformat after close to avoid a double delete
38563833 AVFormatContext* closeFc = fc;
38573834 avformat_close_input (&closeFc);
38583835 fc->iformat = nullptr ;
3859- } else if (fc->oformat != nullptr && !adaptor) // crashes otherwise...
3860- avformat_free_context (fc);
3836+ } else if (fc->oformat != nullptr ) {
3837+ if (fc->pb != nullptr ) {
3838+ if (adaptor)
3839+ avio_context_free (&fc->pb );
3840+ else {
3841+ ret = avio_closep (&fc->pb );
3842+ if (ret < 0 ) {
3843+ printf (" DEBUG: For url '%s', %s" , (fc->url != nullptr ) ? fc->url : " unknown" ,
3844+ avErrorMsg (" error closing IO: " , ret));
3845+ }
3846+ }
3847+ }
3848+ // FIXME this is segfaulting ... why
3849+ /* if (fc->codec_whitelist != nullptr) {
3850+ av_freep(fc->codec_whitelist);
3851+ }
3852+ if (fc->format_whitelist != nullptr) {
3853+ av_freep(fc->format_whitelist);
3854+ }
3855+ if (fc->protocol_whitelist != nullptr) {
3856+ av_freep(fc->protocol_whitelist);
3857+ }
3858+ if (fc->protocol_blacklist != nullptr) {
3859+ av_freep(fc->protocol_blacklist);
3860+ } */
3861+ if (!adaptor) // crashes otherwise...
3862+ avformat_free_context (fc);
3863+ }
38613864}
38623865
38633866napi_value newStream (napi_env env, napi_callback_info info) {
0 commit comments