bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH 02/14] libtrivfs: improve the out of memory handling in add_e


From: Samuel Thibault
Subject: Re: [PATCH 02/14] libtrivfs: improve the out of memory handling in add_el
Date: Sat, 9 Nov 2013 18:49:06 +0100
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Justus Winter, le Fri 08 Nov 2013 21:24:10 +0100, a écrit :
> add_el reallocs two memory regions. If at least one of the operation
> fails, free any region that was successfully resized. Also release the
> lock.
> 
> Found using the Clang Static Analyzer.
> 
> * libtrivfs/dyn-classes.c (add_el): Improve the oom handling.
> ---
>  libtrivfs/dyn-classes.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libtrivfs/dyn-classes.c b/libtrivfs/dyn-classes.c
> index a6bb7de..981a588 100644
> --- a/libtrivfs/dyn-classes.c
> +++ b/libtrivfs/dyn-classes.c
> @@ -104,6 +104,9 @@ add_el (void *el, void (*free_el)(),
>      {
>        if (free_el)
>       (*free_el) (el);
> +      free (new_vec);
> +      free (new_aux_vec);

Mmm, but the caller's pointers would have potentially been freed by the
realloc.  Here it's too late to revert that anyway, so perhaps it'd
rather be

/* Update caller's pointers, at least.  */
if (new_vec)
  *vec = new_vec;
if (new_aux_vec)
  *aux_vec = new_aux_vec;

> +      pthread_mutex_unlock (&dyn_lock);

Ack.

>        /* One of the vectors might be the wrong size, but who cares.  */
>        return ENOMEM;
>      }
> -- 
> 1.7.10.4
> 
> 

-- 
Samuel
Be warned that typing \fBkillall \fIname\fP may not have the desired
effect on non-Linux systems, especially when done by a privileged user.
(From the killall manual page)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]