Commit 81f37d39 authored by Rémi Duraffort's avatar Rémi Duraffort

Better asprintf error handling

parent c2598291
...@@ -1060,9 +1060,16 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1060,9 +1060,16 @@ void update_DownloadReal( update_download_thread_t *p_udt )
l_size = stream_Size( p_stream ); l_size = stream_Size( p_stream );
psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' ); psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
if( !psz_tmpdestfile )
{
msg_Err( p_update->p_libvlc, "The URL %s is false formated", p_update->release.psz_url );
return;
}
else
{
psz_tmpdestfile++; psz_tmpdestfile++;
asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ); if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) != -1 )
{
p_file = utf8_fopen( psz_destfile, "w" ); p_file = utf8_fopen( psz_destfile, "w" );
if( !p_file ) if( !p_file )
{ {
...@@ -1075,9 +1082,11 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1075,9 +1082,11 @@ void update_DownloadReal( update_download_thread_t *p_udt )
if( p_buffer ) if( p_buffer )
{ {
psz_size = size_str( l_size ); psz_size = size_str( l_size );
asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done", p_update->release.psz_url, psz_size, 0.0 ); if( asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done", p_update->release.psz_url, psz_size, 0.0 ) != -1 )
{
i_progress = intf_UserProgress( p_update->p_libvlc, "Downloading ...", psz_status, 0.0, 0 ); i_progress = intf_UserProgress( p_update->p_libvlc, "Downloading ...", psz_status, 0.0, 0 );
free( psz_status ); free( psz_status );
}
while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) && while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
!intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) )
...@@ -1086,30 +1095,37 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1086,30 +1095,37 @@ void update_DownloadReal( update_download_thread_t *p_udt )
l_downloaded += i_read; l_downloaded += i_read;
psz_downloaded = size_str( l_downloaded ); psz_downloaded = size_str( l_downloaded );
asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done", p_update->release.psz_url, if( asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done", p_update->release.psz_url,
psz_size, psz_downloaded, 100.0*(float)l_downloaded/(float)l_size ); psz_size, psz_downloaded, 100.0*(float)l_downloaded/(float)l_size ) != -1 )
{
intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 10.0, 0 ); intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 10.0, 0 );
free( psz_downloaded );
free( psz_status ); free( psz_status );
} }
free( psz_downloaded );
}
free( p_buffer );
/* If the user cancelled the download */ /* If the user cancelled the download */
if( !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) if( !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) )
{ {
asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ); if( asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ) != -1 )
{
intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 100.0, 0 ); intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 100.0, 0 );
free( psz_status ); free( psz_status );
} }
free( p_buffer ); }
free( psz_size ); free( psz_size );
} }
fclose( p_file ); fclose( p_file );
if( intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) if( intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) )
remove( psz_destfile ); remove( psz_destfile );
} }
stream_Delete( p_stream ); free( psz_destfile );
}
}
} }
free( psz_destdir ); free( psz_destdir );
stream_Delete( p_stream );
} }
#endif #endif
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