[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [tor/master 2/2] Fix some XXXXs in connection_add_impl related to bufferevent error checking
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed, 13 Oct 2010 20:37:04 -0400
Subject: Fix some XXXXs in connection_add_impl related to bufferevent error checking
Commit: 3af12a555774c3171330f047c3a1a79826e4ea97
This might make bufferevents more asserty for a while, but they should
make other bugs less likely to go unnoticed.
Noted by Sebastian.
---
src/or/main.c | 36 +++++++++++++++++++-----------------
1 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/src/or/main.c b/src/or/main.c
index 9d116fb..eb5a27a 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -161,7 +161,7 @@ int can_complete_circuit=0;
*
****************************************************************************/
-#ifdef USE_BUFFEREVENTS
+#if 0 && defined(USE_BUFFEREVENTS)
static void
free_old_inbuf(connection_t *conn)
{
@@ -211,7 +211,12 @@ connection_add_impl(connection_t *conn, int is_connecting)
tor_libevent_get_base(),
conn->s,
BEV_OPT_DEFER_CALLBACKS);
- /* XXXX CHECK FOR NULL RETURN! */
+ if (!conn->bufev) {
+ log_warn(LD_BUG, "Unable to create socket bufferevent");
+ smartlist_del(connection_array, conn->conn_array_index);
+ conn->conn_array_index = -1;
+ return -1;
+ }
if (is_connecting) {
/* Put the bufferevent into a "connecting" state so that we'll get
* a "connected" event callback on successful write. */
@@ -223,10 +228,14 @@ connection_add_impl(connection_t *conn, int is_connecting)
tor_assert(conn->s < 0);
if (!conn->bufev) {
struct bufferevent *pair[2] = { NULL, NULL };
- /* XXXX CHECK FOR ERROR RETURN! */
- bufferevent_pair_new(tor_libevent_get_base(),
- BEV_OPT_DEFER_CALLBACKS,
- pair);
+ if (bufferevent_pair_new(tor_libevent_get_base(),
+ BEV_OPT_DEFER_CALLBACKS,
+ pair) < 0) {
+ log_warn(LD_BUG, "Unable to create bufferevent pair");
+ smartlist_del(connection_array, conn->conn_array_index);
+ conn->conn_array_index = -1;
+ return -1;
+ }
tor_assert(pair[0]);
conn->bufev = pair[0];
conn->linked_conn->bufev = pair[1];
@@ -236,18 +245,11 @@ connection_add_impl(connection_t *conn, int is_connecting)
tor_assert(!conn->linked);
}
- if (conn->bufev && conn->inbuf) {
- /* XXX Instead we should assert that there is no inbuf, once we
- * have linked connections using bufferevents. */
- free_old_inbuf(conn);
- }
+ if (conn->bufev)
+ tor_assert(conn->inbuf == NULL);
- if (conn->linked_conn && conn->linked_conn->bufev &&
- conn->linked_conn->inbuf) {
- /* XXX Instead we should assert that there is no inbuf, once we
- * have linked connections using bufferevents. */
- free_old_inbuf(conn->linked_conn);
- }
+ if (conn->linked_conn && conn->linked_conn->bufev)
+ tor_assert(conn->linked_conn->inbuf == NULL);
}
#else
(void) is_connecting;
--
1.7.1