[vlc-commits] input stats: handle malloc error

Jean-Paul Saman git at videolan.org
Tue Oct 13 18:23:40 CEST 2015


vlc | branch: master | Jean-Paul Saman <jpsaman at videolan.org> | Tue Jul 14 16:20:12 2015 +0200| [6ca2e8ca5d9ff0727d85b676ed109119984c5100] | committer: Jean-Baptiste Kempf

input stats: handle malloc error

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6ca2e8ca5d9ff0727d85b676ed109119984c5100
---

 src/input/stats.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/input/stats.c b/src/input/stats.c
index ba13f05..bab6690 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -174,6 +174,9 @@ void stats_Update( counter_t *p_counter, uint64_t val, uint64_t *new_val )
         p_counter->last_update = now;
         /* Insert the new one at the beginning */
         p_new = (counter_sample_t*)malloc( sizeof( counter_sample_t ) );
+        if (unlikely(p_new == NULL))
+            return; /* NOTE: Losing sample here */
+
         p_new->value = val;
         p_new->date = p_counter->last_update;
         INSERT_ELEM( p_counter->pp_samples, p_counter->i_samples,
@@ -192,6 +195,9 @@ void stats_Update( counter_t *p_counter, uint64_t val, uint64_t *new_val )
         {
             counter_sample_t *p_new = (counter_sample_t*)malloc(
                                                sizeof( counter_sample_t ) );
+            if (unlikely(p_new == NULL))
+                return; /* NOTE: Losing sample here */
+
             p_new->value = 0;
 
             INSERT_ELEM( p_counter->pp_samples, p_counter->i_samples,



More information about the vlc-commits mailing list