[svn] commit: r1193 - /trunk/src/lib/cc/session.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Mar 8 02:36:36 UTC 2010


Author: jinmei
Date: Mon Mar  8 02:36:36 2010
New Revision: 1193

Log:
exception safe bug.  use vector instead of an array allocated by new[].

Modified:
    trunk/src/lib/cc/session.cc

Modified: trunk/src/lib/cc/session.cc
==============================================================================
--- trunk/src/lib/cc/session.cc (original)
+++ trunk/src/lib/cc/session.cc Mon Mar  8 02:36:36 2010
@@ -18,6 +18,7 @@
 #include "session.h"
 
 #include <cstdio>
+#include <vector>
 #include <iostream>
 #include <sstream>
 
@@ -196,14 +197,14 @@
 
     // remove the header-length bytes from the total length
     length -= 2;
-    char *buffer = new char[length];
-    ret = read(sock, buffer, length);
-    if (ret != length)
-        throw SessionError("Short read");
-
-    std::string header_wire = std::string(buffer, header_length);
-    std::string body_wire = std::string(buffer + header_length, length - header_length);
-    delete [] buffer;
+    std::vector<char> buffer(length);
+    ret = read(sock, &buffer[0], length);
+    if (ret != length) {
+        throw SessionError("Short read");
+    }
+
+    std::string header_wire = std::string(&buffer[0], header_length);
+    std::string body_wire = std::string(&buffer[0] + header_length, length - header_length);
 
     std::stringstream header_wire_stream;
     header_wire_stream << header_wire;




More information about the bind10-changes mailing list