Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Crash: unguarded lazy init in loader, service cache and avformat when producers open on several threads

Open
#1,317 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@iDoMeteor is already working on this.

Since Oct 1, 2026.

  • #1329 by @iDoMeteor — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c

Research direction

Start by running the linked lazyinit reproduction after reading producer_loader.c, mlt_service.c, and avformat/factory.c at the lazy initialization sites named in the report. Trace the concurrent initialization and cleanup paths for dictionary, normalizers, the service cache, and avformat state. Done means the reproduction remains stable across repeated threaded runs without requiring the warm-up workaround.

Written by the indexing model from the issue text.

Description

Environment: MLT 7.40.0 (Fedora 44 package, x86_64), FFmpeg 8.1.2. The code involved is unchanged on master (0926a75).

Found while building a GTK4 video editor on MLT; the repro below uses only melt/libmlt.

What happens

Several pieces of process-wide MLT state are initialised lazily, on first use, without a lock or a once-guard:

  • producer_loader.c: the static dictionary (create_producer(), if (dictionary == NULL) at line 87) and normalizers (attach_normalizers());
  • mlt_service.c: get_cache() creating the global "caches" properties (line 934);
  • avformat/factory.c: avformat_initialised (line 61).

So the first producers opened on several threads at once can crash: two threads each build the dictionary, one's is freed while the other iterates it, and the same for the others.

Repro

Four threads each open a clip through the default loader and read one frame, straight after mlt_factory_init() (C, 50 lines): https://github.com/iDoMeteor/u-studio-video-editor/tree/70841c3/tools/upstream-repros/mlt/lazy-init-race

ffmpeg -f lavfi -i testsrc2=s=640x360:r=25:d=2 -pix_fmt yuv420p clip.mp4
cc -g lazyinit.c -o lazyinit -pthread $(pkg-config --cflags --libs mlt-framework-7)
for i in $(seq 200); do ./lazyinit clip.mp4 || echo crash; done | grep -c crash       # 31
for i in $(seq 200); do ./lazyinit clip.mp4 warm || echo crash; done | grep -c crash  # 0

31 of 200 runs segfaulted (16 cores). Where, from the core dumps:

Crashing frames Runs
mlt_properties_count ← create_producer ← producer_loader_init (dictionary) 14
mlt_properties_count ← attach_normalizers ← producer_loader_init 11
mlt_properties_get_data/set_data ← get_cache ← mlt_service_cache_put ← producer_avformat_init 4
mlt_frame_close (double free) and mlt_cache_item_close 2

With warm (one open and decode on the main thread before the threads start): 0 of 200.

Expected: opening producers on several threads is safe. Actual: about one run in seven crashes.

Notes

pthread_once (or a mutex) around each of these would fix it. We work around it by opening one producer on the main thread right after mlt_factory_init(). The worker threads in apps (thumbnails, waveforms, probing) are the usual way to hit this.

Dominant language
C
Stars
1.9k
Forks
391
Avg merge
1d 17h
Merged PRs (30d)
12

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mltframework/mlt

All issues in mltframework/mlt

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.