(libT) fix dangling pointer in tor->currentDir when reloading a .resume file from disk

This commit is contained in:
Jordan Lee 2013-01-31 21:57:08 +00:00
parent 1eb2933fc5
commit 9c550b5a78
1 changed files with 6 additions and 0 deletions

View File

@ -728,8 +728,11 @@ loadFromFile (tr_torrent * tor, uint64_t fieldsToLoad)
&& (tr_variantDictFindStr (&top, TR_KEY_destination, &str, &len))
&& (str && *str))
{
const bool is_current_dir = tor->currentDir == tor->downloadDir;
tr_free (tor->downloadDir);
tor->downloadDir = tr_strndup (str, len);
if (is_current_dir)
tor->currentDir = tor->downloadDir;
fieldsLoaded |= TR_FR_DOWNLOAD_DIR;
}
@ -737,8 +740,11 @@ loadFromFile (tr_torrent * tor, uint64_t fieldsToLoad)
&& (tr_variantDictFindStr (&top, TR_KEY_incomplete_dir, &str, &len))
&& (str && *str))
{
const bool is_current_dir = tor->currentDir == tor->incompleteDir;
tr_free (tor->incompleteDir);
tor->incompleteDir = tr_strndup (str, len);
if (is_current_dir)
tor->currentDir = tor->incompleteDir;
fieldsLoaded |= TR_FR_INCOMPLETE_DIR;
}