[pulseaudio-discuss] [PATCH 11/23] sink-input, source-output: Allocate the object early in new()

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Sat Nov 23 09:25:16 PST 2013


On Wed, 2013-11-20 at 11:26 +0200, Tanu Kaskinen wrote:
> The sink input/source output node will have to be created already
> during the routing phase, because doing it later makes it impossible
> to use node-based routing to set the initial routing. When the node is
> created, it will need the sink input/source output pointer, and that's
> why we need to allocate the object already before the routing phase.
> 
> I had to choose which fields to initialize early. I think at least
> index, core and state need to be initialized before passing the object
> to any external code, but I chose to move up the initialization of all
> fields that only require a one-liner.
> 
> I also removed explicit initialization of fields that were just set
> to zero, because pa_msgobject_new() nowadays zeroes the memory anyway.
> ---
>  src/pulsecore/sink-input.c    | 51 +++++++++++++++++--------------------------
>  src/pulsecore/source-output.c | 39 +++++++++++++++------------------
>  2 files changed, 37 insertions(+), 53 deletions(-)
> 
> diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
> index 1f88bfc..7d5ce56 100644
> --- a/src/pulsecore/sink-input.c
> +++ b/src/pulsecore/sink-input.c
> @@ -304,6 +304,25 @@ int pa_sink_input_new(
>      pa_assert(data);
>      pa_assert_ctl_context();
>  
> +    i = pa_msgobject_new(pa_sink_input);
> +    i->parent.parent.free = sink_input_free;
> +    i->parent.process_msg = pa_sink_input_process_msg;
> +    pa_assert_se(pa_idxset_put(core->sink_inputs, i, &i->index) >= 0);
> +    i->core = core;
> +    i->state = PA_SINK_INPUT_INIT;
> +    i->flags = data->flags;
> +    i->module = data->module;
> +    i->client = data->client;
> +    i->origin_sink = data->origin_sink;
> +    i->direct_outputs = pa_idxset_new(NULL, NULL);
> +    i->requested_resample_method = data->resample_method;

Here's a bug that causes crashing. This resample method assignment
shouldn't have been moved up. data->resample_method is modified later,
so the assignment needs to happen later too. I tried to look out for
this kind of issues before moving the initializations up, but apparently
I wasn't careful enough. (The later modification is that if
data->resample_method == PA_RESAMPLER_INVALID, then
data->resample_method is set to i->core->resample_method.)

The same applies for source output too.

-- 
Tanu



More information about the pulseaudio-discuss mailing list