From: Marc-André Lureau <[email protected]> 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).
Signed-off-by: Marc-André Lureau <[email protected]> --- audio/audio_template.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audio/audio_template.h b/audio/audio_template.h index 925a878f6d..7d204d25bc 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -231,6 +231,7 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp) glue(hw->pcm_ops->fini_, TYPE) (hw); glue(s->nb_hw_voices_, TYPE) += 1; glue(audio_pcm_hw_free_resources_ , TYPE) (hw); + object_unref(hw->s); g_free(hw); *hwp = NULL; } @@ -287,7 +288,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioDriver *s, * is guaranteed to be != 0. See the audio_init_nb_voices_* functions. */ hw = g_malloc0(glue(drv->voice_size_, TYPE)); - hw->s = s; + hw->s = AUDIO_DRIVER(object_ref(s)); hw->pcm_ops = drv->pcm_ops; QLIST_INIT (&hw->sw_head); @@ -335,6 +336,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioDriver *s, err1: glue (hw->pcm_ops->fini_, TYPE) (hw); err0: + object_unref(hw->s); g_free (hw); return NULL; } @@ -441,7 +443,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)( } sw = g_new0(SW, 1); - sw->s = s; + sw->s = AUDIO_DRIVER(object_ref(s)); hw = glue(audio_pcm_hw_add_, TYPE)(s, &hw_as); if (!hw) { @@ -461,6 +463,7 @@ err2: glue (audio_pcm_hw_del_sw_, TYPE) (sw); glue (audio_pcm_hw_gc_, TYPE) (&hw); err1: + object_unref(sw->s); g_free(sw); return NULL; } @@ -470,6 +473,8 @@ static void glue (audio_close_, TYPE) (SW *sw) glue (audio_pcm_sw_fini_, TYPE) (sw); glue (audio_pcm_hw_del_sw_, TYPE) (sw); glue (audio_pcm_hw_gc_, TYPE) (&sw->hw); + + object_unref(sw->s); g_free (sw); } -- 2.51.1
