@samitouri / QOSamiQemu / commits / 1002fe3710

audio: keep a strong reference on the backend

Since we are going to convert audio_driver-based backends, we need to properly handle reference counting to allow for a different order of class finalization (for example, pulse class before base driver class). Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Oct 20, 2025 at 14:05 UTC 1002fe3710cc2fda2d49553cf06b16ae46a36044
1 file changed +7 -2
audio/audio_template.h
+7 -2
@@ -231,6 +231,7 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
231 glue(hw->pcm_ops->fini_, TYPE) (hw);
232 glue(s->nb_hw_voices_, TYPE) += 1;
233 glue(audio_pcm_hw_free_resources_ , TYPE) (hw);
234 + object_unref(hw->s);
235 g_free(hw);
236 *hwp = NULL;
237 }
@@ -287,7 +288,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
288 * is guaranteed to be != 0. See the audio_init_nb_voices_* functions.
289 */
290 hw = g_malloc0(glue(drv->voice_size_, TYPE));
290 - hw->s = s;
291 + hw->s = AUDIO_MIXENG_BACKEND(object_ref(s));
292 hw->pcm_ops = drv->pcm_ops;
293
294 QLIST_INIT (&hw->sw_head);
@@ -335,6 +336,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
336 err1:
337 glue (hw->pcm_ops->fini_, TYPE) (hw);
338 err0:
339 + object_unref(hw->s);
340 g_free (hw);
341 return NULL;
342 }
@@ -441,7 +443,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
443 }
444
445 sw = g_new0(SW, 1);
444 - sw->s = s;
446 + sw->s = AUDIO_MIXENG_BACKEND(object_ref(s));
447
448 hw = glue(audio_pcm_hw_add_, TYPE)(s, &hw_as);
449 if (!hw) {
@@ -461,6 +463,7 @@ err2:
463 glue (audio_pcm_hw_del_sw_, TYPE) (sw);
464 glue (audio_pcm_hw_gc_, TYPE) (&hw);
465 err1:
466 + object_unref(sw->s);
467 g_free(sw);
468 return NULL;
469 }
@@ -470,6 +473,8 @@ static void glue (audio_close_, TYPE) (SW *sw)
473 glue (audio_pcm_sw_fini_, TYPE) (sw);
474 glue (audio_pcm_hw_del_sw_, TYPE) (sw);
475 glue (audio_pcm_hw_gc_, TYPE) (&sw->hw);
476 +
477 + object_unref(sw->s);
478 g_free (sw);
479 }
480