Commit a69589d3 authored by Rémi Duraffort's avatar Rémi Duraffort

realrtsp: fix potential memleaks.

parent e7d54bc7
...@@ -115,16 +115,22 @@ static int filter(const char *in, const char *filter, char **out, size_t outlen) ...@@ -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) { static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
sdpplin_stream_t *desc = malloc(sizeof(sdpplin_stream_t)); sdpplin_stream_t *desc;
char *buf = malloc(BUFLEN); char* buf = NULL;
char *decoded = malloc(BUFLEN); char* decoded = NULL;
int handled; int handled;
if( !desc ) return NULL; desc = calloc( 1, sizeof(sdpplin_stream_t) );
memset(desc, 0, sizeof(sdpplin_stream_t)); if( !desc )
return NULL;
buf = malloc( BUFLEN );
if( !buf )
goto error;
if( !buf ) goto error; decoded = malloc( BUFLEN );
if( !decoded ) goto error; if( !decoded )
goto error;
if (filter(*data, "m=", &buf, BUFLEN)) { if (filter(*data, "m=", &buf, BUFLEN)) {
desc->id = strdup(buf); desc->id = strdup(buf);
...@@ -227,32 +233,36 @@ error: ...@@ -227,32 +233,36 @@ error:
return NULL; return NULL;
} }
sdpplin_t *sdpplin_parse(char *data) {
sdpplin_t *desc = malloc(sizeof(sdpplin_t)); sdpplin_t *sdpplin_parse(char *data)
sdpplin_stream_t *stream; {
char *buf=NULL; sdpplin_t* desc;
char *decoded=NULL; sdpplin_stream_t* stream;
char* buf;
char* decoded;
int handled; int handled;
int len; int len;
if( !desc ) return NULL; desc = calloc( 1, sizeof(sdpplin_t) );
buf = malloc(BUFLEN); if( !desc )
if( !buf ) { return NULL;
buf = malloc( BUFLEN );
if( !buf )
{
free( desc ); free( desc );
return NULL; return NULL;
} }
decoded = malloc(BUFLEN);
if( !decoded ) { decoded = malloc( BUFLEN );
if( !decoded )
{
free( buf ); free( buf );
free( desc ); free( desc );
return NULL; return NULL;
} }
desc->stream = NULL; desc->stream = NULL;
memset(desc, 0, sizeof(sdpplin_t));
while (data && *data) { while (data && *data) {
handled=0; handled=0;
...@@ -358,7 +368,8 @@ void sdpplin_free(sdpplin_t *description) { ...@@ -358,7 +368,8 @@ void sdpplin_free(sdpplin_t *description) {
free( description->stream[i] ); free( description->stream[i] );
} }
} }
if( description->stream_count ) free( description->stream ); if( description->stream_count )
free( description->stream );
free( description->owner ); free( description->owner );
free( description->session_name ); free( description->session_name );
...@@ -375,5 +386,5 @@ void sdpplin_free(sdpplin_t *description) { ...@@ -375,5 +386,5 @@ void sdpplin_free(sdpplin_t *description) {
free( description->asm_rule_book ); free( description->asm_rule_book );
free( description->abstract ); free( description->abstract );
free( description->range ); free( description->range );
free(description); free( description );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment