changeset 29577:0ce49cb1b85b

Change real_setup_and_get_header to use goto a single exit path to simplify proper freeing of allocated data.
author reimar
date Wed, 02 Sep 2009 10:10:42 +0000
parents fbed30114410
children b0ee310c2216
files stream/realrtsp/real.c
diffstat 1 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/stream/realrtsp/real.c	Wed Sep 02 09:51:38 2009 +0000
+++ b/stream/realrtsp/real.c	Wed Sep 02 10:10:42 2009 +0000
@@ -427,11 +427,11 @@
 
   char *description=NULL;
   char *session_id=NULL;
-  rmff_header_t *h;
+  rmff_header_t *h = NULL;
   char *challenge1;
   char challenge2[41];
   char checksum[9];
-  char *subscribe;
+  char *subscribe = NULL;
   char *buf = xbuffer_init(256);
   char *mrl=rtsp_get_mrl(rtsp_session);
   unsigned int size;
@@ -513,8 +513,7 @@
         alert);
     }
     rtsp_send_ok(rtsp_session);
-    buf = xbuffer_free(buf);
-    return NULL;
+    goto out;
   }
 
   /* receive description */
@@ -528,8 +527,7 @@
   if (size > MAX_DESC_BUF) {
     mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: Content-length for description too big (> %uMB)!\n",
             MAX_DESC_BUF/(1024*1024) );
-    xbuffer_free(buf);
-    return NULL;
+    goto out;
   }
 
   if (!rtsp_search_answers(rtsp_session,"ETag"))
@@ -544,8 +542,7 @@
   description=malloc(size+1);
 
   if( rtsp_read_data(rtsp_session, description, size) <= 0) {
-    buf = xbuffer_free(buf);
-    return NULL;
+    goto out;
   }
   description[size]=0;
 
@@ -554,9 +551,7 @@
   strcpy(subscribe, "Subscribe: ");
   h=real_parse_sdp(description, &subscribe, bandwidth);
   if (!h) {
-    subscribe = xbuffer_free(subscribe);
-    buf = xbuffer_free(buf);
-    return NULL;
+    goto out;
   }
   rmff_fix_header(h);
 
@@ -619,6 +614,7 @@
   /* and finally send a play request */
   rtsp_request_play(rtsp_session,NULL);
 
+out:
   subscribe = xbuffer_free(subscribe);
   buf = xbuffer_free(buf);
   return h;