diff --git a/libavformat/mov.c b/libavformat/mov.c
index 327a25b..90a99d9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -76,6 +76,9 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
 static int mov_read_mfra(MOVContext *c, AVIOContext *f);
 static int64_t add_ctts_entry(MOVStts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
                               int count, int duration);
+#ifndef DISABLE_TANGUY_PATCH
+static void mov_free_encryption_index(MOVEncryptionIndex **index);
+#endif
 
 static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
                                              unsigned len, const char *key)
@@ -1367,6 +1370,29 @@ static void fix_frag_index_entries(MOVFragmentIndex *frag_index, int index,
     }
 }
 
+#ifndef DISABLE_TANGUY_PATCH
+static void free_curr_frag_streams_encryption_indexes(MOVFragmentIndex *frag_index)
+{
+	MOVFragmentStreamInfo *fsi;
+	MOVFragmentIndexItem *fii;
+
+	if (!frag_index)
+		return;
+
+	if ((frag_index->current < 0) ||
+	    (frag_index->current >= frag_index->nb_items))
+		return;
+
+	fii = &frag_index->item[frag_index->current];
+
+	for (fsi = &fii->stream_info[0];
+	     fsi < &fii->stream_info[fii->nb_stream_info];
+	     fsi++) {
+		mov_free_encryption_index(&fsi->encryption_index);
+	}
+}
+#endif
+
 static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     // Set by mov_read_tfhd(). mov_read_trun() will reject files missing tfhd.
@@ -1389,6 +1415,9 @@ static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     }
     c->fragment.moof_offset = c->fragment.implicit_offset = avio_tell(pb) - 8;
     av_log(c->fc, AV_LOG_TRACE, "moof offset %"PRIx64"\n", c->fragment.moof_offset);
+#ifndef DISABLE_TANGUY_PATCH
+    free_curr_frag_streams_encryption_indexes(&c->frag_index);
+#endif
     c->frag_index.current = update_frag_index(c, c->fragment.moof_offset);
     return mov_read_default(c, pb, atom);
 }
