Commit 7dd25734 authored by Rémi Duraffort's avatar Rémi Duraffort

video_filter_rss: factorize and fix object leaks and memleaks.

parent e6bf1849
...@@ -676,9 +676,10 @@ static int FetchRSS( filter_t *p_filter) ...@@ -676,9 +676,10 @@ static int FetchRSS( filter_t *p_filter)
{ {
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
stream_t *p_stream = NULL; stream_t *p_stream;
xml_t *p_xml = NULL; xml_t *p_xml;
xml_reader_t *p_xml_reader = NULL; xml_reader_t *p_xml_reader;
int i_ret = 1;
char *psz_eltname = NULL; char *psz_eltname = NULL;
char *psz_eltvalue = NULL; char *psz_eltvalue = NULL;
...@@ -724,16 +725,15 @@ static int FetchRSS( filter_t *p_filter) ...@@ -724,16 +725,15 @@ static int FetchRSS( filter_t *p_filter)
if( !p_stream ) if( !p_stream )
{ {
msg_Err( p_filter, "Failed to open %s for reading", p_feed->psz_url ); msg_Err( p_filter, "Failed to open %s for reading", p_feed->psz_url );
xml_Delete( p_xml ); p_xml_reader = NULL;
return 1; goto error;
} }
p_xml_reader = xml_ReaderCreate( p_xml, p_stream ); p_xml_reader = xml_ReaderCreate( p_xml, p_stream );
if( !p_xml_reader ) if( !p_xml_reader )
{ {
msg_Err( p_filter, "Failed to open %s for parsing", p_feed->psz_url ); msg_Err( p_filter, "Failed to open %s for parsing", p_feed->psz_url );
xml_Delete( p_xml ); goto error;
return 1;
} }
i_item = 0; i_item = 0;
...@@ -746,15 +746,14 @@ static int FetchRSS( filter_t *p_filter) ...@@ -746,15 +746,14 @@ static int FetchRSS( filter_t *p_filter)
{ {
// Error // Error
case -1: case -1:
return 1; goto error;
case XML_READER_STARTELEM: case XML_READER_STARTELEM:
free( psz_eltname ); free( psz_eltname );
psz_eltname = xml_ReaderName( p_xml_reader ); psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) if( !psz_eltname )
{ goto error;
return 1;
}
# ifdef RSS_DEBUG # ifdef RSS_DEBUG
msg_Dbg( p_filter, "element name: %s", psz_eltname ); msg_Dbg( p_filter, "element name: %s", psz_eltname );
# endif # endif
...@@ -839,12 +838,10 @@ static int FetchRSS( filter_t *p_filter) ...@@ -839,12 +838,10 @@ static int FetchRSS( filter_t *p_filter)
case XML_READER_ENDELEM: case XML_READER_ENDELEM:
free( psz_eltname ); free( psz_eltname );
psz_eltname = NULL;
psz_eltname = xml_ReaderName( p_xml_reader ); psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) if( !psz_eltname )
{ goto error;
return 1;
}
# ifdef RSS_DEBUG # ifdef RSS_DEBUG
msg_Dbg( p_filter, "element end : %s", psz_eltname ); msg_Dbg( p_filter, "element end : %s", psz_eltname );
# endif # endif
...@@ -858,8 +855,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -858,8 +855,7 @@ static int FetchRSS( filter_t *p_filter)
{ {
b_is_image = false; b_is_image = false;
} }
free( psz_eltname ); FREENULL( psz_eltname );
psz_eltname = NULL;
break; break;
case XML_READER_TEXT: case XML_READER_TEXT:
...@@ -867,13 +863,13 @@ static int FetchRSS( filter_t *p_filter) ...@@ -867,13 +863,13 @@ static int FetchRSS( filter_t *p_filter)
psz_eltvalue = xml_ReaderValue( p_xml_reader ); psz_eltvalue = xml_ReaderValue( p_xml_reader );
if( !psz_eltvalue ) if( !psz_eltvalue )
{ {
return 1; goto error;
} }
else else
{ {
char *psz_clean; char *psz_clean = removeWhiteChars( psz_eltvalue );
psz_clean = removeWhiteChars( psz_eltvalue ); free( psz_eltvalue );
free( psz_eltvalue ); psz_eltvalue = psz_clean; psz_eltvalue = psz_clean;
} }
# ifdef RSS_DEBUG # ifdef RSS_DEBUG
msg_Dbg( p_filter, " text : <%s>", psz_eltvalue ); msg_Dbg( p_filter, " text : <%s>", psz_eltvalue );
...@@ -899,8 +895,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -899,8 +895,7 @@ static int FetchRSS( filter_t *p_filter)
} }
else else
{ {
free( psz_eltvalue ); FREENULL( psz_eltvalue );
psz_eltvalue = NULL;
} }
} }
else if( b_is_image == true ) else if( b_is_image == true )
...@@ -912,8 +907,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -912,8 +907,7 @@ static int FetchRSS( filter_t *p_filter)
} }
else else
{ {
free( psz_eltvalue ); FREENULL( psz_eltvalue );
psz_eltvalue = NULL;
} }
} }
else else
...@@ -942,8 +936,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -942,8 +936,7 @@ static int FetchRSS( filter_t *p_filter)
} }
else else
{ {
free( psz_eltvalue ); FREENULL( psz_eltvalue );
psz_eltvalue = NULL;
} }
} }
break; break;
...@@ -956,13 +949,28 @@ static int FetchRSS( filter_t *p_filter) ...@@ -956,13 +949,28 @@ static int FetchRSS( filter_t *p_filter)
p_feed->p_pic = LoadImage( p_filter, p_feed->psz_image ); p_feed->p_pic = LoadImage( p_filter, p_feed->psz_image );
} }
if( p_xml_reader && p_xml ) xml_ReaderDelete( p_xml, p_xml_reader ); xml_ReaderDelete( p_xml, p_xml_reader );
if( p_stream ) stream_Delete( p_stream ); stream_Delete( p_stream );
msg_Dbg( p_filter, "done with %s RSS/Atom feed", p_feed->psz_url ); msg_Dbg( p_filter, "done with %s RSS/Atom feed", p_feed->psz_url );
} }
if( p_xml ) xml_Delete( p_xml );
free( psz_eltname );
free( psz_eltvalue );
xml_Delete( p_xml );
return 0; return 0;
error:
free( psz_eltname );
free( psz_eltvalue );
if( p_xml_reader )
xml_ReaderDelete( p_xml, p_xml_reader );
if( p_stream )
stream_Delete( p_stream );
if( p_xml )
xml_Delete( p_xml );
return i_ret;
} }
/**************************************************************************** /****************************************************************************
......
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