2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed memory leak in decoderawstring()
	* src/bencode.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-12-14 05:42:32 +00:00
parent b618ada28a
commit 9b197e97d3
2 changed files with 8 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed memory leak in decoderawstring()
* src/bencode.cc
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added missing #ifdef guard. Added uc() function for String and Added missing #ifdef guard. Added uc() function for String and

View File

@ -335,19 +335,19 @@ static std::string decoderawstring(std::istream& ss)
size_t length; size_t length;
ss >> length; ss >> length;
if(!ss) { if(!ss) {
throw RecoverableException("Integer expected but none found."); throw RecoverableException("A positive integer expected but none found.");
} }
// TODO check length, it must be less than or equal to INT_MAX // TODO check length, it must be less than or equal to INT_MAX
checkdelim(ss); checkdelim(ss);
char* buf = new char[length]; char* buf = new char[length];
ss.read(buf, length); ss.read(buf, length);
std::string str(&buf[0], &buf[length]);
delete [] buf;
if(ss.gcount() != static_cast<int>(length)) { if(ss.gcount() != static_cast<int>(length)) {
throw RecoverableException throw RecoverableException
(StringFormat("Expected %lu bytes of data, but only %d read.", (StringFormat("Expected %lu bytes of data, but only %d read.",
static_cast<unsigned long>(length), ss.gcount()).str()); static_cast<unsigned long>(length), ss.gcount()).str());
} }
std::string str(&buf[0], &buf[length]);
delete [] buf;
return str; return str;
} }