Browse Source

fixed exception unsafeness bug

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1208 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya 15 years ago
parent
commit
7496b7c519
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/lib/cc/session.cc

+ 7 - 7
src/lib/cc/session.cc

@@ -157,17 +157,17 @@ Session::recvmsg(ElementPtr& msg, bool nonblock)
     if (header_length != length) {
     if (header_length != length) {
         throw SessionError("Received non-empty body where only a header expected");
         throw SessionError("Received non-empty body where only a header expected");
     }
     }
-    
-    char *buffer = new char[length];
-    ret = read(sock, buffer, length);
-    if (ret != length)
+
+    std::vector<char> buffer(length);
+    ret = read(sock, &buffer[0], length);
+    if (ret != length) {
         throw SessionError("Short read");
         throw SessionError("Short read");
+    }
 
 
-    std::string wire = std::string(buffer, length);
-    delete [] buffer;
+    std::string wire = std::string(&buffer[0], length);
 
 
     std::stringstream wire_stream;
     std::stringstream wire_stream;
-    wire_stream <<wire;
+    wire_stream << wire;
 
 
     msg = Element::fromWire(wire_stream, length);
     msg = Element::fromWire(wire_stream, length);