Skip to content

Commit 85c9444

Browse files
SiegeLordExSiegeLord
authored andcommitted
Fix a race between detaching instances from mixers and reading from them.
Previously it was possible for the vector size to decrease/increase unpredictably, causing random wrong slots to be deleted instead of the intended one, which sometimes would leave detached instances in the vector.
1 parent a0aa2c9 commit 85c9444

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

addons/audio/kcm_instance.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,20 @@ void _al_kcm_detach_from_parent(ALLEGRO_SAMPLE_INSTANCE *spl)
124124
mixer = spl->parent.u.mixer;
125125

126126
/* Search through the streams and check for this one */
127+
maybe_lock_mutex(mixer->ss.mutex);
127128
for (i = _al_vector_size(&mixer->streams) - 1; i >= 0; i--) {
128129
ALLEGRO_SAMPLE_INSTANCE **slot = _al_vector_ref(&mixer->streams, i);
129130

130131
if (*slot == spl) {
131-
maybe_lock_mutex(mixer->ss.mutex);
132-
133132
_al_vector_delete_at(&mixer->streams, i);
134133
spl->parent.u.mixer = NULL;
135134
_al_kcm_stream_set_mutex(spl, NULL);
136135

137136
spl->spl_read = NULL;
138-
139-
maybe_unlock_mutex(mixer->ss.mutex);
140-
141137
break;
142138
}
143139
}
140+
maybe_unlock_mutex(mixer->ss.mutex);
144141

145142
al_free(spl->matrix);
146143
spl->matrix = NULL;

0 commit comments

Comments
 (0)