tsoding / musializer

Music Visualizer
MIT License
877 stars 92 forks source link

Race condition in Microphone capture #94

Open cpiber opened 6 months ago

cpiber commented 6 months ago

In start_capture, you initialize capturing. You do this by setting p->capturing = true, and then initializing the WAV writer.

https://github.com/tsoding/musializer/blob/9ddb4d26990ee9a7a5354f3ff054fb6f2e350162/src/plug.c#L1260-L1270

However, in the callback, you simply use the WAV writer as soon as p->capturing is true. Meaning that you might be using an uninitialized WAV (Note that this exact thing happened in the last stream, though the code looked a little different, when you tried to use a debugger).

https://github.com/tsoding/musializer/blob/9ddb4d26990ee9a7a5354f3ff054fb6f2e350162/src/plug.c#L487-L491