[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] prop224: Use a const pointer for the cache lookup entry



commit 3f29688bdff3d6aa0b47ee7080995f44dbb579de
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Thu Sep 15 14:13:18 2016 -0400

    prop224: Use a const pointer for the cache lookup entry
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/directory.c       |  4 +---
 src/or/hs_cache.c        | 16 ++++++++--------
 src/or/hs_cache.h        |  2 +-
 src/test/test_hs_cache.c |  7 ++-----
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/or/directory.c b/src/or/directory.c
index a3aa276..75fc103 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -3400,7 +3400,7 @@ handle_get_hs_descriptor_v3(dir_connection_t *conn,
                             const get_handler_args_t *args)
 {
   int retval;
-  char *desc_str = NULL;
+  const char *desc_str = NULL;
   const char *pubkey_str = NULL;
   const char *url = args->url;
 
@@ -3434,8 +3434,6 @@ handle_get_hs_descriptor_v3(dir_connection_t *conn,
   connection_write_to_buf(desc_str, strlen(desc_str), TO_CONN(conn));
 
  done:
-  tor_free(desc_str);
-
   return 0;
 }
 
diff --git a/src/or/hs_cache.c b/src/or/hs_cache.c
index 6d33201..ec98b47 100644
--- a/src/or/hs_cache.c
+++ b/src/or/hs_cache.c
@@ -142,13 +142,13 @@ cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc)
   return -1;
 }
 
-/* Using the query which is the blinded key for a descriptor version 3, lookup
- * in our directory cache the entry. If found, 1 is returned and desc_out is
- * populated with a newly allocated string being the encoded descriptor. If
- * not found, 0 is returned and desc_out is untouched. On error, a negative
- * value is returned and desc_out is untouched. */
+/* Using the query which is the base64 encoded blinded key of a version 3
+ * descriptor, lookup in our directory cache the entry. If found, 1 is
+ * returned and desc_out is populated with a newly allocated string being the
+ * encoded descriptor. If not found, 0 is returned and desc_out is untouched.
+ * On error, a negative value is returned and desc_out is untouched. */
 static int
-cache_lookup_v3_as_dir(const char *query, char **desc_out)
+cache_lookup_v3_as_dir(const char *query, const char **desc_out)
 {
   int found = 0;
   ed25519_public_key_t blinded_key;
@@ -167,7 +167,7 @@ cache_lookup_v3_as_dir(const char *query, char **desc_out)
   if (entry != NULL) {
     found = 1;
     if (desc_out) {
-      *desc_out = tor_strdup(entry->encoded_desc);
+      *desc_out = entry->encoded_desc;
     }
   }
 
@@ -270,7 +270,7 @@ hs_cache_store_as_dir(const char *desc)
  * untouched. */
 int
 hs_cache_lookup_as_dir(uint32_t version, const char *query,
-                       char **desc_out)
+                       const char **desc_out)
 {
   int found;
 
diff --git a/src/or/hs_cache.h b/src/or/hs_cache.h
index 466c33d..88f84c1 100644
--- a/src/or/hs_cache.h
+++ b/src/or/hs_cache.h
@@ -48,7 +48,7 @@ size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
  * right function. */
 int hs_cache_store_as_dir(const char *desc);
 int hs_cache_lookup_as_dir(uint32_t version, const char *query,
-                           char **desc_out);
+                           const char **desc_out);
 
 #ifdef HS_CACHE_PRIVATE
 
diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c
index f3776ac..e3a3fda 100644
--- a/src/test/test_hs_cache.c
+++ b/src/test/test_hs_cache.c
@@ -131,7 +131,8 @@ test_directory(void *arg)
 {
   int ret;
   size_t oom_size;
-  char *desc_out, *desc1_str;
+  char *desc1_str;
+  const char *desc_out;
   hs_descriptor_t *desc1;
 
   (void) arg;
@@ -158,7 +159,6 @@ test_directory(void *arg)
     ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
     tt_int_op(ret, OP_EQ, 1);
     tt_str_op(desc_out, OP_EQ, desc1_str);
-    tor_free(desc_out);
     /* Tell our OOM to run and to at least remove a byte which will result in
      * removing the descriptor from our cache. */
     oom_size = hs_cache_handle_oom(time(NULL), 1);
@@ -186,7 +186,6 @@ test_directory(void *arg)
     ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
     tt_int_op(ret, OP_EQ, 1);
     tt_str_op(desc_out, OP_EQ, desc1_str);
-    tor_free(desc_out);
     /* We should NOT find our zero lifetime desc in our cache. */
     ret = hs_cache_lookup_as_dir(3,
                                  helper_get_hsdir_query(desc_zero_lifetime),
@@ -221,7 +220,6 @@ test_directory(void *arg)
     tt_int_op(ret, OP_EQ, 0);
     ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
     tt_int_op(ret, OP_EQ, 1);
-    tor_free(desc_out);
     /* Bump revision counter. */
     desc1->plaintext_data.revision_counter++;
     ret = hs_desc_encode_descriptor(desc1, &new_desc_str);
@@ -232,7 +230,6 @@ test_directory(void *arg)
     ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
     tt_int_op(ret, OP_EQ, 1);
     tt_str_op(desc_out, OP_EQ, new_desc_str);
-    tor_free(desc_out);
     tor_free(new_desc_str);
   }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits