[PATCH 1/2] memblock: fix memory leak when pa_shm_create_rw fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good catch!

An alternative solution (and IMHO better one) would be to move the two
lines allocating the mutex and semaphore below the if-block that can
return. That way you avoid the memory-leak situation alltogether.

Maarten

2011/8/15 Lu Guanqun <guanqun.lu at intel.com>:
> Signed-off-by: Lu Guanqun <guanqun.lu at intel.com>
> ---
> ?src/pulsecore/memblock.c | ? ?2 ++
> ?1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
> index e34a739..332fcb7 100644
> --- a/src/pulsecore/memblock.c
> +++ b/src/pulsecore/memblock.c
> @@ -728,6 +728,8 @@ pa_mempool* pa_mempool_new(pa_bool_t shared, size_t size) {
> ? ? }
>
> ? ? if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) {
> + ? ? ? ?pa_semaphore_free(p->semaphore);
> + ? ? ? ?pa_mutex_free(p->mutex);
> ? ? ? ? pa_xfree(p);
> ? ? ? ? return NULL;
> ? ? }
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux