[or-cvs] connection_new() can"t ever fail

Roger Dingledine arma at seul.org
Sat Sep 27 07:28:47 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	buffers.c connection.c connection_edge.c connection_or.c 
	cpuworker.c directory.c dns.c 
Log Message:
connection_new() can't ever fail


Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- buffers.c	26 Sep 2003 10:03:49 -0000	1.39
+++ buffers.c	27 Sep 2003 07:28:44 -0000	1.40
@@ -44,7 +44,7 @@
 
 /* Create and return a new buf of size 'size'
  */
-buf_t *buf_new_with_capacity(size_t size) {
+static buf_t *buf_new_with_capacity(size_t size) {
   buf_t *buf;
   buf = (buf_t*)tor_malloc(sizeof(buf_t));
   buf->buf = (char *)tor_malloc(size);

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- connection.c	26 Sep 2003 10:03:49 -0000	1.104
+++ connection.c	27 Sep 2003 07:28:44 -0000	1.105
@@ -80,9 +80,8 @@
   memset(conn,0,sizeof(connection_t)); /* zero it out to start */
 
   conn->type = type;
-  if(!(conn->inbuf = buf_new()) ||
-     !(conn->outbuf = buf_new())) 
-    return NULL;
+  conn->inbuf = buf_new();
+  conn->outbuf = buf_new();
 
   conn->receiver_bucket = 50000; /* should be enough to do the handshake */
   conn->bandwidth = conn->receiver_bucket / 10; /* give it a default */
@@ -149,10 +148,6 @@
   set_socket_nonblocking(s);
 
   conn = connection_new(type);
-  if(!conn) {
-    log_fn(LOG_WARNING,"connection_new failed. Giving up.");
-    return -1;
-  }
   conn->s = s;
   conn->receiver_bucket = -1; /* non-cell connections don't do receiver buckets */
   conn->bandwidth = -1;
@@ -200,10 +195,6 @@
   set_socket_nonblocking(news);
 
   newconn = connection_new(new_type);
-  if(!newconn) {
-    log_fn(LOG_WARNING,"connection_new failed. Giving up.");
-    return 0;
-  }
   newconn->s = news;
 
   if(!connection_speaks_cells(newconn)) {

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- connection_edge.c	26 Sep 2003 10:03:50 -0000	1.26
+++ connection_edge.c	27 Sep 2003 07:28:44 -0000	1.27
@@ -548,10 +548,6 @@
 
   log_fn(LOG_DEBUG,"Creating new exit connection.");
   n_stream = connection_new(CONN_TYPE_EXIT);
-  if(!n_stream) {
-    log_fn(LOG_WARNING,"connection_new failed. Dropping.");
-    return 0;
-  }
 
   memcpy(n_stream->stream_id, cell->payload + RELAY_HEADER_SIZE, STREAM_ID_SIZE);
   n_stream->address = strdup(cell->payload + RELAY_HEADER_SIZE + STREAM_ID_SIZE);

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- connection_or.c	26 Sep 2003 10:03:50 -0000	1.55
+++ connection_or.c	27 Sep 2003 07:28:44 -0000	1.56
@@ -104,10 +104,6 @@
     return conn;
 
   conn = connection_new(CONN_TYPE_OR);
-  if(!conn) {
-    log_fn(LOG_WARNING,"connection_new failed; skipping.");
-    return NULL;
-  }
 
   /* set up conn so it's got all the data we need to remember */
   connection_or_init_conn_from_router(conn, router);

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cpuworker.c	26 Sep 2003 10:03:50 -0000	1.7
+++ cpuworker.c	27 Sep 2003 07:28:44 -0000	1.8
@@ -179,10 +179,6 @@
   close(fd[1]); /* we don't need the worker's side of the pipe */
 
   conn = connection_new(CONN_TYPE_CPUWORKER);
-  if(!conn) {
-    close(fd[0]);
-    return -1;
-  }
 
   set_socket_nonblocking(fd[0]);
 

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- directory.c	26 Sep 2003 10:03:50 -0000	1.33
+++ directory.c	27 Sep 2003 07:28:44 -0000	1.34
@@ -43,8 +43,6 @@
     log_fn(LOG_DEBUG,"initiating directory upload");
 
   conn = connection_new(CONN_TYPE_DIR);
-  if(!conn)
-    return;
 
   /* set up conn so it's got all the data we need to remember */
   conn->addr = router->addr;

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- dns.c	26 Sep 2003 10:03:50 -0000	1.27
+++ dns.c	27 Sep 2003 07:28:44 -0000	1.28
@@ -382,10 +382,6 @@
   close(fd[1]); /* we don't need the worker's side of the pipe */
 
   conn = connection_new(CONN_TYPE_DNSWORKER);
-  if(!conn) {
-    close(fd[0]);
-    return -1;
-  }
 
   set_socket_nonblocking(fd[0]);
 



More information about the tor-commits mailing list