[vlc-commits] realrtsp: minor refactor + bounds check of `rtsp_unschedule_all` and `rtsp_free_answers`

Filip Roséen git at videolan.org
Fri Feb 26 20:46:48 CET 2016


vlc/vlc-2.2 | branch: master | Filip Roséen <filip at atch.se> | Thu Feb 25 10:12:38 2016 +0100| [fdebbaaaa6e4f592c89b358313446f141b937f3d] | committer: Jean-Baptiste Kempf

realrtsp: minor refactor + bounds check of `rtsp_unschedule_all` and `rtsp_free_answers`

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.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit b1f9f8758d14e75fefcfd7cde1ee038f6106529f)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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 18e9966..1467fbf 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);
 }



More information about the vlc-commits mailing list