[vlc-devel] commit: realrtsp: fix potential memleaks. ( Rémi Duraffort )

git version control git at videolan.org
Wed Dec 17 20:52:24 CET 2008


vlc | branch: 0.9-bugfix | Rémi Duraffort <ivoire at videolan.org> | Fri Dec 12 21:43:38 2008 +0100| [f563abe56e1a4f44a49c218009c3894fb2744217] | committer: Jean-Baptiste Kempf 

realrtsp: fix potential memleaks.
(cherry picked from commit a69589d375efb7839e4729f53581d21e0635dc95)

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

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

 modules/access/rtsp/real_sdpplin.c |   61 +++++++++++++++++++++---------------
 1 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/modules/access/rtsp/real_sdpplin.c b/modules/access/rtsp/real_sdpplin.c
index be950c2..458803e 100644
--- a/modules/access/rtsp/real_sdpplin.c
+++ b/modules/access/rtsp/real_sdpplin.c
@@ -115,16 +115,22 @@ static int filter(const char *in, const char *filter, char **out, size_t outlen)
 
 static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
 
-  sdpplin_stream_t *desc = malloc(sizeof(sdpplin_stream_t));
-  char      *buf = malloc(BUFLEN);
-  char      *decoded = malloc(BUFLEN);
-  int       handled;
+  sdpplin_stream_t *desc;
+  char* buf = NULL;
+  char* decoded = NULL;
+  int handled;
 
-  if( !desc ) return NULL;
-  memset(desc, 0, sizeof(sdpplin_stream_t));
+  desc = calloc( 1, sizeof(sdpplin_stream_t) );
+  if( !desc )
+    return NULL;
 
-  if( !buf ) goto error;
-  if( !decoded ) goto error;
+  buf = malloc( BUFLEN );
+  if( !buf )
+    goto error;
+
+  decoded = malloc( BUFLEN );
+  if( !decoded )
+    goto error;
 
   if (filter(*data, "m=", &buf, BUFLEN)) {
     desc->id = strdup(buf);
@@ -227,32 +233,36 @@ error:
   return NULL;
 }
 
-sdpplin_t *sdpplin_parse(char *data) {
 
-  sdpplin_t        *desc = malloc(sizeof(sdpplin_t));
-  sdpplin_stream_t *stream;
-  char             *buf=NULL;
-  char             *decoded=NULL;
-  int              handled;
-  int              len;
+sdpplin_t *sdpplin_parse(char *data)
+{
+  sdpplin_t*        desc;
+  sdpplin_stream_t* stream;
+  char*             buf;
+  char*             decoded;
+  int               handled;
+  int               len;
 
-  if( !desc ) return NULL;
-  buf = malloc(BUFLEN);
-  if( !buf ) {
+  desc = calloc( 1, sizeof(sdpplin_t) );
+  if( !desc )
+    return NULL;
+
+  buf = malloc( BUFLEN );
+  if( !buf )
+  {
     free( desc );
     return NULL;
   }
-  decoded = malloc(BUFLEN);
-  if( !decoded ) {
+
+  decoded = malloc( BUFLEN );
+  if( !decoded )
+  {
     free( buf );
     free( desc );
     return NULL;
   }
-
   desc->stream = NULL;
 
-  memset(desc, 0, sizeof(sdpplin_t));
-
   while (data && *data) {
     handled=0;
 
@@ -358,7 +368,8 @@ void sdpplin_free(sdpplin_t *description) {
       free( description->stream[i] );
     }
   }
-  if( description->stream_count ) free( description->stream );
+  if( description->stream_count )
+    free( description->stream );
 
   free( description->owner );
   free( description->session_name );
@@ -375,5 +386,5 @@ void sdpplin_free(sdpplin_t *description) {
   free( description->asm_rule_book );
   free( description->abstract );
   free( description->range );
-  free(description);
+  free( description );
 }




More information about the vlc-devel mailing list