]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #4395 "Crash when removing data for incomplete magnetized torrent file...
authorJordan Lee <jordan@transmissionbt.com>
Sat, 30 Jul 2011 13:11:06 +0000 (13:11 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 30 Jul 2011 13:11:06 +0000 (13:11 +0000)
libtransmission/torrent.c

index 36bbc0b2bc982aa972b9e5691317f2c1a99d6cf6..2e1726075658a60f470103b7edc7d6cbbecbd75e 100644 (file)
@@ -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; f<tor->info.fileCount; ++f ) {
         tr_ptrArrayInsertSorted( &torrentFiles, tr_strdup( tor->info.files[f].name ), vstrcmp );