]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
vallgrind memtool/hellgrind clean.
authorYuri Schaeffer <yuri@nlnetlabs.nl>
Mon, 27 Jul 2015 13:23:42 +0000 (13:23 +0000)
committerYuri Schaeffer <yuri@nlnetlabs.nl>
Mon, 27 Jul 2015 13:23:42 +0000 (13:23 +0000)
git-svn-id: file:///svn/unbound/branches/edns-subnet@3460 be551aaa-1e26-0410-a405-d3ace91eadb9

edns-subnet/subnetmod.c
edns-subnet/subnetmod.h

index fb82dd4009f0a9fea55eb9f4aeb27b83861292c6..11fa815f2b1e71434a966f909585e509f91fb02a 100644 (file)
@@ -74,6 +74,7 @@ subnetmod_init(struct module_env *env, int id)
                log_err("malloc failure");
                return 0;
        }
+       alloc_init(&sn_env->alloc, NULL, 0);
        env->modinfo[id] = (void*)sn_env;
        /* Copy msg_cache settings for now */
        sn_env->subnet_msg_cache = slabhash_create(env->cfg->msg_cache_slabs,
@@ -82,6 +83,8 @@ subnetmod_init(struct module_env *env, int id)
                        query_entry_delete, subnet_data_delete, NULL);
        if(!sn_env->subnet_msg_cache) {
                log_err("subnet: could not create cache");
+               free(sn_env);
+               env->modinfo[id] = NULL;
                return 0;
        }
        return 1;
@@ -95,6 +98,7 @@ subnetmod_deinit(struct module_env *env, int id)
                return;
        sn_env = (struct subnet_env*)env->modinfo[id];
        slabhash_delete(sn_env->subnet_msg_cache);
+       alloc_clear(&sn_env->alloc);
        free(sn_env);
        env->modinfo[id] = NULL;
 }
@@ -113,8 +117,8 @@ cp_edns_bad_response(struct edns_data *target, struct edns_data *source)
 static void
 delfunc(void *envptr, void *elemptr) {
        struct reply_info *elem = (struct reply_info *)elemptr;
-       struct module_env *env = (struct module_env *)envptr;
-       reply_info_parsedelete(elem, env->alloc);
+       struct subnet_env *env = (struct subnet_env *)envptr;
+       reply_info_parsedelete(elem, &env->alloc);
 }
 
 static size_t
@@ -131,7 +135,7 @@ sizefunc(void *elemptr) {
  * NULL on failure to create. */
 static struct addrtree* 
 get_tree(struct subnet_msg_cache_data *data, struct edns_data *edns, 
-       struct module_env *env)
+       struct subnet_env *env)
 {
        struct addrtree *tree;
        if (edns->subnet_addr_fam == EDNSSUBNET_ADDRFAM_IP4) {
@@ -155,8 +159,8 @@ update_cache(struct module_qstate *qstate, int id)
        struct addrtree *tree;
        struct reply_info *rep;
        struct query_info qinf;
-       struct slabhash *subnet_msg_cache = 
-               ((struct subnet_env*)qstate->env->modinfo[id])->subnet_msg_cache;
+       struct subnet_env *sne = qstate->env->modinfo[id];
+       struct slabhash *subnet_msg_cache = sne->subnet_msg_cache;
        struct edns_data *edns = &qstate->edns_client_in;
        size_t i;
        
@@ -188,12 +192,12 @@ update_cache(struct module_qstate *qstate, int id)
                }
        }
        /** Step 2, find the correct tree */
-       if (!(tree = get_tree(lru_entry->data, edns, qstate->env))) {
+       if (!(tree = get_tree(lru_entry->data, edns, sne))) {
                if (acquired_lock) lock_rw_unlock(&lru_entry->lock);
                log_err("Subnet cache insertion failed");
                return;
        }
-       rep = reply_info_copy(qstate->return_msg->rep, qstate->env->alloc, NULL);
+       rep = reply_info_copy(qstate->return_msg->rep, &sne->alloc, NULL);
        
        /* store RRsets */
        for(i=0; i<rep->rrset_count; i++) {
@@ -227,6 +231,7 @@ lookup_and_reply(struct module_qstate *qstate, int id)
        struct edns_data *edns = &qstate->edns_client_in;
        struct addrtree *tree;
        struct addrnode *node;
+       int scope;
        
        if (iq) iq->qinfo_hash = h; /** Might be useful on cache miss */
        e = slabhash_lookup(sne->subnet_msg_cache, h, &qstate->qinfo, 1);
@@ -248,6 +253,7 @@ lookup_and_reply(struct module_qstate *qstate, int id)
        qstate->return_msg = tomsg(env, &qstate->qinfo,
                (struct reply_info *)node->elem, qstate->region, *env->now,
                env->scratch);
+       scope = node->scope;
        lock_rw_unlock(&e->lock);
        
        if (!qstate->return_msg) { /** TTL expired */
@@ -256,7 +262,7 @@ lookup_and_reply(struct module_qstate *qstate, int id)
        
        if (edns->subnet_downstream) { /* relay to interested client */
                memcpy(&qstate->edns_client_out, edns, sizeof(struct edns_data));
-               qstate->edns_client_out.subnet_scope_mask = node->scope;
+               qstate->edns_client_out.subnet_scope_mask = scope;
        }
        return 1;
 }
index 3c52fa27492e35b44d986f9bcde6162f50b61d00..cbfd0233dd77a1fef0f342b815c80c8b91696b21 100644 (file)
@@ -14,6 +14,7 @@
 #define SUBNETMOD_H
 #include "util/module.h"
 #include "services/outbound_list.h"
+#include "util/alloc.h"
 #include "util/net_help.h"
 #include "util/storage/slabhash.h"
 #include "edns-subnet/addrtree.h"
@@ -26,6 +27,8 @@ struct subnet_env {
         * key: struct query_info*
         * data: struct subnet_msg_cache_data* */
        struct slabhash* subnet_msg_cache;
+       /** allocation service */
+       struct alloc_cache alloc;
 };
 
 struct subnet_msg_cache_data {