[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)
- Re: [PATCH 06/14] proc: turn {init, add}str, compare_versions into normal functions, (continued)
- [PATCH 03/14] proc: remove declaration of nested functions from proc.h, Justus Winter, 2013/11/08
- [PATCH 05/14] proc: turn reap into a normal function, Justus Winter, 2013/11/08
- [PATCH 08/14] proc: fix a use-after-free error, Justus Winter, 2013/11/08
- [PATCH 13/14] mach-defpager: include errno.h, Justus Winter, 2013/11/08
- [PATCH 02/14] libtrivfs: improve the out of memory handling in add_el, Justus Winter, 2013/11/08
- Re: [PATCH 02/14] libtrivfs: improve the out of memory handling in add_el,
Samuel Thibault <=
- [PATCH 12/14] mach-defpager: turn dealloc_direct into a normal function, Justus Winter, 2013/11/08
- Re: [PATCH 01/14] term: fix error handling in hurdio_mdmctl, Samuel Thibault, 2013/11/09