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);
+      pthread_mutex_unlock (&dyn_lock);
       /* One of the vectors might be the wrong size, but who cares.  */
       return ENOMEM;
     }
-- 
1.7.10.4


Reply via email to