[or-cvs] r18096: {tor} Fix up (I hope) most ot the things that coverity suddenly cl (in tor/trunk/src: common or)

nickm at seul.org nickm at seul.org
Tue Jan 13 14:43:51 UTC 2009


Author: nickm
Date: 2009-01-13 09:43:51 -0500 (Tue, 13 Jan 2009)
New Revision: 18096

Modified:
   tor/trunk/src/common/torgzip.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/routerlist.c
   tor/trunk/src/or/routerparse.c
   tor/trunk/src/or/test.c
Log:
Fix up (I hope) most ot the things that coverity suddenly claimed were REVERSE_INULL.  This is what we get for bragging about being down to 0 issues.

Modified: tor/trunk/src/common/torgzip.c
===================================================================
--- tor/trunk/src/common/torgzip.c	2009-01-13 14:43:46 UTC (rev 18095)
+++ tor/trunk/src/common/torgzip.c	2009-01-13 14:43:51 UTC (rev 18096)
@@ -76,14 +76,14 @@
   tor_assert(in);
   tor_assert(in_len < UINT_MAX);
 
+  *out = NULL;
+
   if (method == GZIP_METHOD && !is_gzip_supported()) {
     /* Old zlib version don't support gzip in deflateInit2 */
     log_warn(LD_BUG, "Gzip not supported with zlib %s", ZLIB_VERSION);
-    return -1;
+    goto err;
   }
 
-  *out = NULL;
-
   stream = tor_malloc_zero(sizeof(struct z_stream_s));
   stream->zalloc = Z_NULL;
   stream->zfree = Z_NULL;

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2009-01-13 14:43:46 UTC (rev 18095)
+++ tor/trunk/src/or/control.c	2009-01-13 14:43:51 UTC (rev 18096)
@@ -823,24 +823,21 @@
 handle_control_getconf(control_connection_t *conn, uint32_t body_len,
                        const char *body)
 {
-  smartlist_t *questions = NULL;
-  smartlist_t *answers = NULL;
-  smartlist_t *unrecognized = NULL;
+  smartlist_t *questions = smartlist_create();
+  smartlist_t *answers = smartlist_create();
+  smartlist_t *unrecognized = smartlist_create();
   char *msg = NULL;
   size_t msg_len;
   or_options_t *options = get_options();
   int i, len;
 
-  questions = smartlist_create();
   (void) body_len; /* body is nul-terminated; so we can ignore len. */
   smartlist_split_string(questions, body, " ",
                          SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
-  answers = smartlist_create();
-  unrecognized = smartlist_create();
-  SMARTLIST_FOREACH(questions, char *, q,
+  SMARTLIST_FOREACH(questions, const char *, q,
   {
     if (!option_is_recognized(q)) {
-      smartlist_add(unrecognized, q);
+      smartlist_add(unrecognized, (char*) q);
     } else {
       config_line_t *answer = option_get_assignment(options,q);
       if (!answer) {
@@ -886,15 +883,12 @@
     connection_write_str_to_buf("250 OK\r\n", conn);
   }
 
-  if (answers) {
-    SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
-    smartlist_free(answers);
-  }
-  if (questions) {
-    SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
-    smartlist_free(questions);
-  }
+  SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
+  smartlist_free(answers);
+  SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
+  smartlist_free(questions);
   smartlist_free(unrecognized);
+
   tor_free(msg);
 
   return 0;
@@ -2020,18 +2014,15 @@
 handle_control_getinfo(control_connection_t *conn, uint32_t len,
                        const char *body)
 {
-  smartlist_t *questions = NULL;
-  smartlist_t *answers = NULL;
-  smartlist_t *unrecognized = NULL;
+  smartlist_t *questions = smartlist_create();
+  smartlist_t *answers = smartlist_create();
+  smartlist_t *unrecognized = smartlist_create();
   char *msg = NULL, *ans = NULL;
   int i;
   (void) len; /* body is nul-terminated, so it's safe to ignore the length. */
 
-  questions = smartlist_create();
   smartlist_split_string(questions, body, " ",
                          SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
-  answers = smartlist_create();
-  unrecognized = smartlist_create();
   SMARTLIST_FOREACH(questions, const char *, q,
   {
     if (handle_getinfo_helper(conn, q, &ans) < 0) {
@@ -2075,14 +2066,10 @@
   connection_write_str_to_buf("250 OK\r\n", conn);
 
  done:
-  if (answers) {
-    SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
-    smartlist_free(answers);
-  }
-  if (questions) {
-    SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
-    smartlist_free(questions);
-  }
+  SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
+  smartlist_free(answers);
+  SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
+  smartlist_free(questions);
   smartlist_free(unrecognized);
   tor_free(msg);
 

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2009-01-13 14:43:46 UTC (rev 18095)
+++ tor/trunk/src/or/routerlist.c	2009-01-13 14:43:51 UTC (rev 18096)
@@ -619,10 +619,14 @@
   int had_any;
   int force = flags & RRS_FORCE;
 
-  if (!force && !router_should_rebuild_store(store))
-    return 0;
-  if (!routerlist)
-    return 0;
+  if (!force && !router_should_rebuild_store(store)) {
+    r = 0;
+    goto done;
+  }
+  if (!routerlist) {
+    r = 0;
+    goto done;
+  }
 
   if (store->type == EXTRAINFO_STORE)
     had_any = !eimap_isempty(routerlist->extra_info_map);

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2009-01-13 14:43:46 UTC (rev 18095)
+++ tor/trunk/src/or/routerparse.c	2009-01-13 14:43:51 UTC (rev 18096)
@@ -1468,7 +1468,7 @@
 
   if (router_get_extrainfo_hash(s, digest) < 0) {
     log_warn(LD_DIR, "Couldn't compute router hash.");
-    return NULL;
+    goto err;
   }
   tokens = smartlist_create();
   area = memarea_new();

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2009-01-13 14:43:46 UTC (rev 18095)
+++ tor/trunk/src/or/test.c	2009-01-13 14:43:51 UTC (rev 18096)
@@ -2401,13 +2401,12 @@
 static void
 test_util_pqueue(void)
 {
-  smartlist_t *sl = NULL;
+  smartlist_t *sl = smartlist_create();
   int (*cmp)(const void *, const void*);
 #define OK() smartlist_pqueue_assert_ok(sl, cmp)
 
   cmp = _compare_strings_for_pqueue;
 
-  sl = smartlist_create();
   smartlist_pqueue_add(sl, cmp, (char*)"cows");
   smartlist_pqueue_add(sl, cmp, (char*)"zebras");
   smartlist_pqueue_add(sl, cmp, (char*)"fish");
@@ -2451,8 +2450,8 @@
 #undef OK
 
  done:
-  if (sl)
-    smartlist_free(sl);
+
+  smartlist_free(sl);
 }
 
 /** Run unit tests for compression functions */
@@ -3921,17 +3920,16 @@
   char address2[] = "aaaaaaaaaaaaaaaa.onion";
   char address3[] = "fooaddress.exit";
   char address4[] = "www.torproject.org";
-  rend_service_descriptor_t *d1 = NULL, *d2 = NULL;
+  rend_service_descriptor_t *d1 =
+    tor_malloc_zero(sizeof(rend_service_descriptor_t));
+  rend_service_descriptor_t *d2 = NULL;
   char *encoded = NULL;
   size_t len;
-  crypto_pk_env_t *pk1 = NULL, *pk2 = NULL;
   time_t now;
   int i;
-  pk1 = pk_generate(0);
-  pk2 = pk_generate(1);
+  crypto_pk_env_t *pk1 = pk_generate(0), *pk2 = pk_generate(1);
 
   /* Test unversioned (v0) descriptor */
-  d1 = tor_malloc_zero(sizeof(rend_service_descriptor_t));
   d1->pk = crypto_pk_dup_key(pk1);
   now = time(NULL);
   d1->timestamp = now;
@@ -3967,6 +3965,13 @@
   test_assert(EXIT_HOSTNAME == parse_extended_hostname(address3));
   test_assert(NORMAL_HOSTNAME == parse_extended_hostname(address4));
 
+  crypto_free_pk_env(pk1);
+  crypto_free_pk_env(pk2);
+  pk1 = pk2 = NULL;
+  rend_service_descriptor_free(d1);
+  rend_service_descriptor_free(d2);
+  d1 = d2 = NULL;
+
  done:
   if (pk1)
     crypto_free_pk_env(pk1);
@@ -4530,6 +4535,10 @@
     test_eq(gen_info->port, par_info->port);
   }
 
+  rend_service_descriptor_free(parsed);
+  rend_service_descriptor_free(generated);
+  parsed = generated = NULL;
+
  done:
   if (descs) {
     for (i = 0; i < smartlist_len(descs); i++)



More information about the tor-commits mailing list