Browse Source

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

	Fixed memory leak in decoderawstring()
	* src/bencode.cc
Tatsuhiro Tsujikawa 17 years ago
parent
commit
9b197e97d3
2 changed files with 8 additions and 3 deletions
  1. 5 0
      ChangeLog
  2. 3 3
      src/bencode.cc

+ 5 - 0
ChangeLog

@@ -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>
 
 	Added missing #ifdef guard.  Added uc() function for String and

+ 3 - 3
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<int>(length)) {
     throw RecoverableException
       (StringFormat("Expected %lu bytes of data, but only %d read.",
 		    static_cast<unsigned long>(length), ss.gcount()).str());
   }
-  std::string str(&buf[0], &buf[length]);
-  delete [] buf;
   return str;
 }