[pulseaudio-discuss] [PATCH 1/2] memblock: Detect block ID collisions in pa_memimport_get

David Henningsson david.henningsson at canonical.com
Fri Dec 5 03:56:54 PST 2014



On 2014-12-05 12:51, Peter Meerwald wrote:
>
>> Make sure we don't hand out the wrong block, in case we have the
>> same block ID in different SHM segments.
>
> this adds two checks: for block type and that the shm id matches
>
> using %u in pa_log() would save the (int) casts;

Ok

> maybe both, shm_id and
> memory.id could be logged?

This would require two logs because if b->type != PA_MEMBLOCK_IMPORTED 
then there is no memory.id.

>
> thanks, p.
>
>> Signed-off-by: David Henningsson <david.henningsson at canonical.com>
>> ---
>>   src/pulsecore/memblock.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
>> index f8b008f..ca24dec 100644
>> --- a/src/pulsecore/memblock.c
>> +++ b/src/pulsecore/memblock.c
>> @@ -1017,6 +1017,11 @@ pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_i
>>       pa_mutex_lock(i->mutex);
>>
>>       if ((b = pa_hashmap_get(i->blocks, PA_UINT32_TO_PTR(block_id)))) {
>> +        if (b->type != PA_MEMBLOCK_IMPORTED || b->per_type.imported.segment->memory.id != shm_id) {
>> +            pa_log("Cannot import memory due to to block ID collision (block %d, shm id %d)!", (int) block_id, (int) shm_id);
>> +            b = NULL;
>> +            goto finish;
>> +        }
>>           pa_memblock_ref(b);
>>           goto finish;
>>       }
>>
>

-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


More information about the pulseaudio-discuss mailing list