浏览代码

Touch up App/net.{cpp,hpp}

Including fixing memory leaks when async_reads fail
Ian Goldberg 1 年之前
父节点
当前提交
9302a275e5
共有 2 个文件被更改,包括 8 次插入9 次删除
  1. 8 6
      App/net.cpp
  2. 0 3
      App/net.hpp

+ 8 - 6
App/net.cpp

@@ -12,6 +12,7 @@
 
 #define VERBOSE_NET
 // #define DEBUG_NET_CLIENTS
+#define PROFILE_NET_CLIENTS
 
 #define CEILDIV(x,y) (((x)+(y)-1)/(y))
 
@@ -242,7 +243,7 @@ uint64_t NetIO::reset_bytes_sent()
 }
 
 /*
-    Receive clients dropped off messages, i.e. a CLIENT_MESSAGE_BUNDLE
+    Receive clients' dropped-off messages, i.e. a CLIENT_MESSAGE_BUNDLE
 */
 
 void NetIO::ing_receive_msgbundle(tcp::socket* csocket, clientid_t c_simid)
@@ -257,10 +258,10 @@ void NetIO::ing_receive_msgbundle(tcp::socket* csocket, clientid_t c_simid)
             if(ec == boost::asio::error::eof) {
                 // Client connection terminated so we delete this socket
                 delete(csocket);
-            }
-            else {
+            } else {
                 printf("Error ing_receive_msgbundle : %s\n", ec.message().c_str());
             }
+            free(msgbundle);
             return;
         }
 
@@ -328,9 +329,9 @@ void NetIO::ing_authenticate_new_client(tcp::socket* csocket,
             } else {
                 printf("Error ing_auth_new_client : %s\n", ec.message().c_str());
             }
+            free(auth_message);
             return;
-        }
-        else {
+        } else {
             clientid_t c_simid = *((clientid_t *)(auth_message));
             // Read the authentication token
             unsigned char *auth_ptr = auth_message + sizeof(clientid_t);
@@ -386,6 +387,7 @@ void NetIO::stg_authenticate_new_client(tcp::socket* csocket,
             } else {
                 printf("Error stg_auth_new_client: %s\n", ec.message().c_str());
             }
+            free(auth_message);
             return;
         }
         else {
@@ -634,7 +636,7 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
 
 
     if(myconf.roles & ROLE_STORAGE) {
-        // Setup the client sockets
+        // Set up the client sockets
         // Compute no_of_clients per storage_server
         uint32_t num_users = config.user_count;
         NodeConfig nc;

+ 0 - 3
App/net.hpp

@@ -12,9 +12,6 @@
 #include "appconfig.hpp"
 #include "../Enclave/enclave_api.h"
 
-// #define DEBUG_NET_CLIENTS
-#define PROFILE_NET_CLIENTS
-
 // The inter-node (untrusted node to untrusted node) communication
 // protocol is as follows.  Nodes are numbered 0 through num_nodes-1.
 // At startup time, each pair of nodes establishes a TCP connection by