> + if (be_synth->fClientCount == 0) { > + delete be_synth; > + be_synth = NULL; > + } Theorically, there is still a race condition on be_synth value here. What about: if (be_synth->fClientCount == 0) { BMidiSynth* midiSynth = be_synth; be_synth = NULL; delete midiSynth; } ?