pulse: get rid of a number of assert()s
PATCH 1/4 pulse: get rid of a number of assert()s
Instead of hitting an assert when any of the plugin functions is called in an invalid context we should return a clean error to make sure programs are not unnecessarily aborted.
This should fix issues such as http://pulseaudio.org/ticket/595
--- pulse/ctl_pulse.c | 35 +++++++++++++++++------ pulse/pcm_pulse.c | 79 +++++++++++++++++++++++++++++++++++++++++------------ pulse/pulse.c | 34 ++++++++++++++++------- 3 files changed, 111 insertions(+), 37 deletions(-)
pulse/ctl_pulse.c +26 -9
@@ -125,8 +125,9 @@ static void event_cb(pa_context * c, pa_subscription_event_type_t t,pa_operation *o;assert (ctl); -assert (ctl->p); -assert (ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return ; o =pa_context_get_sink_info_by_name (ctl->p->context, ctl->sink, sink_info_cb, ctl);
@@ -148,8 +149,9 @@ static int pulse_update_volume(snd_ctl_pulse_t * ctl)pa_operation *o;assert (ctl); -assert (ctl->p); -assert (ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; o =pa_context_get_sink_info_by_name (ctl->p->context, ctl->sink, sink_info_cb, ctl);
@@ -203,6 +205,9 @@ static int pulse_elem_list(snd_ctl_ext_t * ext, unsigned int offset,assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; +snd_ctl_elem_id_set_interface (id,SND_CTL_ELEM_IFACE_MIXER );pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -260,7 +265,9 @@ static int pulse_get_attribute(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,return -EINVAL ;assert (ctl); -assert (ctl->p); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -311,7 +318,9 @@ static int pulse_read_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,pa_cvolume *vol =NULL ;assert (ctl); -assert (ctl->p); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -361,7 +370,9 @@ static int pulse_write_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,pa_cvolume *vol =NULL ;assert (ctl); -assert (ctl->p && ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -465,6 +476,9 @@ static void pulse_subscribe_events(snd_ctl_ext_t * ext, int subscribe)assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return ; +pa_threaded_mainloop_lock (ctl->p->mainloop); ctl->subscribed = !!(subscribe &SND_CTL_EVENT_MASK_VALUE );
@@ -481,6 +495,9 @@ static int pulse_read_event(snd_ctl_ext_t * ext, snd_ctl_elem_id_t * id,assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; +pa_threaded_mainloop_lock (ctl->p->mainloop);if (!ctl->updated || !ctl->subscribed)
@@ -525,8 +542,8 @@ static int pulse_ctl_poll_revents(snd_ctl_ext_t * ext, struct pollfd *pfd,snd_ctl_pulse_t *ctl = ext->private_data;int err =0 ; -assert (ctl); -assert (ctl->p); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
pulse/pcm_pulse.c +61 -18
184 lines not on this page · raw message
pulse/pulse.c +24 -10
@@ -32,8 +32,9 @@ int pulse_check_connection(snd_pulse_t * p)pa_context_state_t state;assert (p); -assert (p->context); -assert (p->mainloop); + +if (!p->context || !p->mainloop) +return -EBADFD ; state =pa_context_get_state (p->context);
@@ -77,8 +78,12 @@ int pulse_wait_operation(snd_pulse_t * p, pa_operation * o) {assert (p);assert (o); -assert (p->state ==PULSE_STATE_READY ); -assert (p->mainloop); + +if (p->state !=PULSE_STATE_READY ) +return -EBADFD ; + +if (!p->mainloop) +return -EBADFD ;for (;;) {int err;
@@ -103,8 +108,12 @@ int pulse_wait_stream_state(snd_pulse_t * p, pa_stream * stream,assert (p);assert (stream); -assert (p->state ==PULSE_STATE_READY ); -assert (p->mainloop); + +if (p->state !=PULSE_STATE_READY ) +return -EBADFD ; + +if (!p->mainloop) +return -EBADFD ;for (;;) {int err;
@@ -197,7 +206,9 @@ snd_pulse_t *pulse_new(void) p->context =pa_context_new (pa_threaded_mainloop_get_api (p->mainloop), buf); -assert (p->context); + +if (!p->context) + goto fail;pa_context_set_state_callback (p->context, context_state_cb, p);
@@ -246,9 +257,12 @@ int pulse_connect(snd_pulse_t * p, const char *server)int err;assert (p); -assert (p->context); -assert (p->mainloop); -assert (p->state ==PULSE_STATE_INIT ); + +if (!p->context || !p->mainloop) +return -EBADFD ; + +if (p->state !=PULSE_STATE_INIT ) +return -EBADFD ;pa_threaded_mainloop_lock (p->mainloop);
Signature · 10 lines
1.6.3.3 Lennart -- Lennart Poettering Red Hat, Inc. lennart [at] poettering [dot] net ICQ# 11060553 http://0pointer.net/lennart/ GnuPG 0x1A015CC4
'Twas brillig, and Lennart Poettering at 31/07/09 15:01 did gyre and gimble:
Quoted 17 lines
Instead of hitting an assert when any of the plugin functions is called in an invalid context we should return a clean error to make sure programs are not unnecessarily aborted.
This should fix issues such as http://pulseaudio.org/ticket/595
--- pulse/ctl_pulse.c | 35 +++++++++++++++++------ pulse/pcm_pulse.c | 79 +++++++++++++++++++++++++++++++++++++++++------------ pulse/pulse.c | 34 ++++++++++++++++------- 3 files changed, 111 insertions(+), 37 deletions(-)pulse/ctl_pulse.c +0
-0
pulse/ctl_pulse.c static int pulse_ctl_poll_revents(snd_ctl_ext_t * ext, struct pollfd *pfd, · line 549
Quoted 10 lines
pulse/ctl_pulse.c +2
-2@@ -525,8 +542,8 @@ static int pulse_ctl_poll_revents(snd_ctl_ext_t * ext, struct pollfd *pfd,snd_ctl_pulse_t *ctl = ext->private_data;int err =0 ; -assert (ctl); -assert (ctl->p); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
Just a smidge overzealous in this one (only one I spotted).
Couldn't find these commits in your alsa-plugins clone atgit://git.0pointer.de/alsa-plugins.git so couldn't create a followup patch so here it is inline (against 1.2.20 so line numbers may be off):
--- alsa-plugins-1.0.20/pulse/ctl_pulse.c~ 2009-07-31 15:39:22.000000000
+0100
+++ alsa-plugins-1.0.20/pulse/ctl_pulse.c 2009-07-31 15:47:32.000000000
+0100
@@ -542,6 +542,8 @@
snd_ctl_pulse_t *ctl = ext->private_data;
int err = 0;
+ assert(ctl);
+
if (!ctl->p || !ctl->p->mainloop || !ctl->p->context)
return -EBADFD;
Col.
Signature · 10 lines
Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/]
Quoted 9 lines · Colin Guthrie
Couldn't find these commits in your alsa-plugins clone at
git://git.0pointer.de/alsa-plugins.gitso couldn't create a followup patch so here it is inline (against 1.2.20 so line numbers may be off):--- alsa-plugins-1.0.20/pulse/ctl_pulse.c~ 2009-07-31 15:39:22.000000000
+0100
+++alsa-plugins-1.0.20/pulse/ctl_pulse.c2009-07-31 15:47:32.000000000
+0100
Review line 549
Quoted 8 lines
(quoted diff) +2
-0@@ -542,6 +542,8 @@ snd_ctl_pulse_t *ctl = ext->private_data; int err = 0; + assert(ctl); + if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) return -EBADFD;
See attachment for a version that incorporates this mini fix.
Lennart
Signature · 3 lines
Lennart Poettering Red Hat, Inc. lennart [at] poettering [dot] net ICQ# 11060553 http://0pointer.net/lennart/ GnuPG 0x1A015CC4
Quoted 1 line
From
5ba1cc327b329ae518c3413e65b44945d5d8f919Mon Sep 17 00:00:00 2001
From: Lennart Poettering <[email protected]>
Date: Fri, 31 Jul 2009 15:25:44 +0200
Subject: [PATCH] pulse: get rid of a number of assert()s
Instead of hitting an assert when any of the plugin functions is called in an invalid context we should return a clean error to make sure programs are not unnecessarily aborted.
This should fix issues such as http://pulseaudio.org/ticket/595
--- pulse/ctl_pulse.c | 35 ++++++++++++++++++----- pulse/pcm_pulse.c | 79 +++++++++++++++++++++++++++++++++++++++++------------ pulse/pulse.c | 34 ++++++++++++++++------- 3 files changed, 112 insertions(+), 36 deletions(-)
pulse/ctl_pulse.c +27 -8
@@ -125,8 +125,9 @@ static void event_cb(pa_context * c, pa_subscription_event_type_t t,pa_operation *o;assert (ctl); -assert (ctl->p); -assert (ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return ; o =pa_context_get_sink_info_by_name (ctl->p->context, ctl->sink, sink_info_cb, ctl);
@@ -148,8 +149,9 @@ static int pulse_update_volume(snd_ctl_pulse_t * ctl)pa_operation *o;assert (ctl); -assert (ctl->p); -assert (ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; o =pa_context_get_sink_info_by_name (ctl->p->context, ctl->sink, sink_info_cb, ctl);
@@ -203,6 +205,9 @@ static int pulse_elem_list(snd_ctl_ext_t * ext, unsigned int offset,assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; +snd_ctl_elem_id_set_interface (id,SND_CTL_ELEM_IFACE_MIXER );pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -260,7 +265,9 @@ static int pulse_get_attribute(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,return -EINVAL ;assert (ctl); -assert (ctl->p); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -311,7 +318,9 @@ static int pulse_read_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,pa_cvolume *vol =NULL ;assert (ctl); -assert (ctl->p); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -361,7 +370,9 @@ static int pulse_write_integer(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key,pa_cvolume *vol =NULL ;assert (ctl); -assert (ctl->p && ctl->p->context); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
@@ -465,6 +476,9 @@ static void pulse_subscribe_events(snd_ctl_ext_t * ext, int subscribe)assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return ; +pa_threaded_mainloop_lock (ctl->p->mainloop); ctl->subscribed = !!(subscribe &SND_CTL_EVENT_MASK_VALUE );
@@ -481,6 +495,9 @@ static int pulse_read_event(snd_ctl_ext_t * ext, snd_ctl_elem_id_t * id,assert (ctl); +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ; +pa_threaded_mainloop_lock (ctl->p->mainloop);if (!ctl->updated || !ctl->subscribed)
@@ -526,7 +543,9 @@ static int pulse_ctl_poll_revents(snd_ctl_ext_t * ext, struct pollfd *pfd,int err =0 ;assert (ctl); -assert (ctl->p); + +if (!ctl->p || !ctl->p->mainloop || !ctl->p->context) +return -EBADFD ;pa_threaded_mainloop_lock (ctl->p->mainloop);
pulse/pcm_pulse.c +61 -18
184 lines not on this page · raw message
pulse/pulse.c +24 -10
@@ -32,8 +32,9 @@ int pulse_check_connection(snd_pulse_t * p)pa_context_state_t state;assert (p); -assert (p->context); -assert (p->mainloop); + +if (!p->context || !p->mainloop) +return -EBADFD ; state =pa_context_get_state (p->context);
@@ -77,8 +78,12 @@ int pulse_wait_operation(snd_pulse_t * p, pa_operation * o) {assert (p);assert (o); -assert (p->state ==PULSE_STATE_READY ); -assert (p->mainloop); + +if (p->state !=PULSE_STATE_READY ) +return -EBADFD ; + +if (!p->mainloop) +return -EBADFD ;for (;;) {int err;
@@ -103,8 +108,12 @@ int pulse_wait_stream_state(snd_pulse_t * p, pa_stream * stream,assert (p);assert (stream); -assert (p->state ==PULSE_STATE_READY ); -assert (p->mainloop); + +if (p->state !=PULSE_STATE_READY ) +return -EBADFD ; + +if (!p->mainloop) +return -EBADFD ;for (;;) {int err;
@@ -197,7 +206,9 @@ snd_pulse_t *pulse_new(void) p->context =pa_context_new (pa_threaded_mainloop_get_api (p->mainloop), buf); -assert (p->context); + +if (!p->context) + goto fail;pa_context_set_state_callback (p->context, context_state_cb, p);
@@ -246,9 +257,12 @@ int pulse_connect(snd_pulse_t * p, const char *server)int err;assert (p); -assert (p->context); -assert (p->mainloop); -assert (p->state ==PULSE_STATE_INIT ); + +if (!p->context || !p->mainloop) +return -EBADFD ; + +if (p->state !=PULSE_STATE_INIT ) +return -EBADFD ;pa_threaded_mainloop_lock (p->mainloop);
Signature · 1 line
1.6.3.3
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 3 lines · Colin Guthrie
Couldn't find these commits in your alsa-plugins clone at
git://git.0pointer.de/alsa-plugins.gitso couldn't create a followup patch so here it is inline (against 1.2.20 so line numbers may be off):
My git tree is now updated.
Lennart
Signature · 3 lines
Lennart Poettering Red Hat, Inc. lennart [at] poettering [dot] net ICQ# 11060553 http://0pointer.net/lennart/ GnuPG 0x1A015CC4
Takashi Iwai
AppliedAt Fri, 31 Jul 2009 16:01:33 +0200,
Quoted 6 lines · Lennart Poettering
Instead of hitting an assert when any of the plugin functions is called in an invalid context we should return a clean error to make sure programs are not unnecessarily aborted.
This should fix issues such as http://pulseaudio.org/ticket/595
Applied all four patches now. Thanks!
Takashi