[vlc-devel] [PATCH 12/13] modules/access/rtsp: minor refactor + bounds check of `rtsp_unschedule_all` and `rtsp_free_answers`

Filip Roséen filip at atch.se
Thu Feb 25 10:12:38 CET 2016


Fixed bounds check in `rtsp_unschedule_field` and `rtsp_free_answers`. Since
both functions share a common goal a (`static`) helper function has been
introduced.

---
 modules/access/rtsp/rtsp.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/modules/access/rtsp/rtsp.c b/modules/access/rtsp/rtsp.c
index 5af2638..3072055 100644
--- a/modules/access/rtsp/rtsp.c
+++ b/modules/access/rtsp/rtsp.c
@@ -695,23 +695,28 @@ void rtsp_unschedule_field( rtsp_client_t *rtsp, const char *needle )
     }
 }
 
+static void pp_free_helper_ (char **pptr, int max_length) {
+  int i;
+
+  for (i = 0; i < max_length; ++i) {
+    if (pptr[i] == NULL)
+      break;
+
+    free (pptr[i]);
+    pptr[i] = NULL;
+  }
+}
+
 /*
  * unschedule all fields
  */
 
 void rtsp_unschedule_all( rtsp_client_t *rtsp )
 {
-    char **ptr;
-
-    if( !rtsp->p_private->scheduled ) return;
-    ptr = rtsp->p_private->scheduled;
+  if (rtsp->p_private == NULL)
+    return;
 
-    while( *ptr )
-    {
-        free( *ptr );
-        *ptr = NULL;
-        ptr++;
-    }
+  pp_free_helper_ (rtsp->p_private->scheduled, MAX_FIELDS);
 }
 /*
  * free answers
@@ -719,15 +724,8 @@ void rtsp_unschedule_all( rtsp_client_t *rtsp )
 
 void rtsp_free_answers( rtsp_client_t *rtsp )
 {
-    char **answer;
-
-    if( !rtsp->p_private->answers ) return;
-    answer = rtsp->p_private->answers;
+  if (rtsp->p_private == NULL)
+    return;
 
-    while( *answer )
-    {
-        free( *answer );
-        *answer = NULL;
-        answer++;
-    }
+  pp_free_helper_ (rtsp->p_private->answers, MAX_FIELDS);
 }
-- 
2.7.1



More information about the vlc-devel mailing list