diff --git a/ChangeLog b/ChangeLog index 9c8d812e..fe441ce3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-14 Tatsuhiro Tsujikawa + + Fixed memory leak in decoderawstring() + * src/bencode.cc + 2008-12-14 Tatsuhiro Tsujikawa Added missing #ifdef guard. Added uc() function for String and diff --git a/src/bencode.cc b/src/bencode.cc index ec60544f..a635e01f 100644 --- a/src/bencode.cc +++ b/src/bencode.cc @@ -335,19 +335,19 @@ static std::string decoderawstring(std::istream& ss) size_t length; ss >> length; 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 checkdelim(ss); char* buf = new char[length]; ss.read(buf, length); + std::string str(&buf[0], &buf[length]); + delete [] buf; if(ss.gcount() != static_cast(length)) { throw RecoverableException (StringFormat("Expected %lu bytes of data, but only %d read.", static_cast(length), ss.gcount()).str()); } - std::string str(&buf[0], &buf[length]); - delete [] buf; return str; }