fix: memory leak in magnet parsing (#1222)

* Fix memory leak in magnet parsing

* Update libtransmission/magnet.c

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* Lint

Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
Tom Richards 2020-05-11 20:57:06 -04:00 committed by GitHub
parent fa6df52d58
commit a82e728ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -174,7 +174,7 @@ tr_magnet_info* tr_magnetParse(char const* uri)
}
}
if (vallen > 0 && keylen == 2 && memcmp(key, "dn", 2) == 0)
if (displayName == NULL && vallen > 0 && keylen == 2 && memcmp(key, "dn", 2) == 0)
{
displayName = tr_http_unescape(val, vallen);
}
@ -212,6 +212,20 @@ tr_magnet_info* tr_magnetParse(char const* uri)
info->webseeds = tr_memdup(ws, sizeof(char*) * wsCount);
memcpy(info->hash, sha1, sizeof(uint8_t) * SHA_DIGEST_LENGTH);
}
else
{
for (int i = 0; i < trCount; i++)
{
tr_free(tr[i]);
}
for (int i = 0; i < wsCount; i++)
{
tr_free(ws[i]);
}
tr_free(displayName);
}
return info;
}