From 8ae478a62f7255d3e9efd01613a756b4e03297fe Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 30 Jul 2011 13:11:06 +0000 Subject: [PATCH] (trunk libT) #4395 "Crash when removing data for incomplete magnetized torrent file" -- fixed. --- libtransmission/torrent.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 36bbc0b2b..2e1726075 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -2711,16 +2711,23 @@ static void deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) { int i, n; + char * tmp; + char * root; char ** s; tr_file_index_t f; + const char * cpch; + const char * firstFile; tr_ptrArray torrentFiles = TR_PTR_ARRAY_INIT; tr_ptrArray folders = TR_PTR_ARRAY_INIT; tr_ptrArray dirtyFolders = TR_PTR_ARRAY_INIT; /* dirty == contains non-torrent files */ - const char * firstFile = tor->info.files[0].name; - const char * cpch = strchr( firstFile, TR_PATH_DELIMITER ); - char * tmp = cpch ? tr_strndup( firstFile, cpch - firstFile ) : NULL; - char * root = tr_buildPath( tor->currentDir, tmp, NULL ); + if( !tr_torrentHasMetadata( tor ) ) + return; + + firstFile = tor->info.files[0].name; + cpch = strchr( firstFile, TR_PATH_DELIMITER ); + tmp = cpch ? tr_strndup( firstFile, cpch - firstFile ) : NULL; + root = tr_buildPath( tor->currentDir, tmp, NULL ); for( f=0; finfo.fileCount; ++f ) { tr_ptrArrayInsertSorted( &torrentFiles, tr_strdup( tor->info.files[f].name ), vstrcmp );