]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- in testcode, free async ids, initialise array, and check for null
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 13 Sep 2018 09:45:07 +0000 (09:45 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 13 Sep 2018 09:45:07 +0000 (09:45 +0000)
  pointer during test of the test.  And use exit for return to note
  irregular program stop.

git-svn-id: file:///svn/unbound/trunk@4897 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testcode/asynclook.c
testcode/fake_event.c
testcode/perf.c
testcode/pktview.c
testcode/replay.c
testcode/unitneg.c

index 7cbc6ab265ec3cd4e2041ee98f68a74f8133cf9c..95b3cfb65c3b0ab7c7d1bc896a240bcadd68d20a 100644 (file)
@@ -4,6 +4,9 @@
        - free memory leaks in config strlist and str2list insert functions.
        - do not move unused argv variable after getopt.
        - Remove unused if clause in testcode.
+       - in testcode, free async ids, initialise array, and check for null
+         pointer during test of the test.  And use exit for return to note
+         irregular program stop.
 
 11 September 2018: Wouter
        - Fixed unused return value warnings in contrib/fastrpz.patch for
index 06bcf5ab862a89502f9946930f905c41ef8c43ad..9a74dbb842bbefd59c2eddb61a326bdad3e0229d 100644 (file)
@@ -182,6 +182,8 @@ struct ext_thr_info {
        char** argv;
        /** number of queries to do */
        int numq;
+       /** list of ids to free once threads are done */
+       struct track_id* id_list;
 };
 
 /** if true, we are testing against 'localhost' and extra checking is done */
@@ -309,6 +311,7 @@ ext_thread(void* arg)
                for(i=0; i<inf->numq; i++) {
                        lock_basic_init(&async_ids[i].lock);
                }
+               inf->id_list = async_ids;
        }
        for(i=0; i<inf->numq; i++) {
                if(async_ids) {
@@ -347,14 +350,6 @@ ext_thread(void* arg)
        /* if these locks are destroyed, or if the async_ids is freed, then
           a use-after-free happens in another thread.
           The allocation is only part of this test, though. */
-       /*
-       if(async_ids) {
-               for(i=0; i<inf->numq; i++) {
-                       lock_basic_destroy(&async_ids[i].lock);
-               }
-       }
-       free(async_ids);
-       */
        
        return NULL;
 }
@@ -375,6 +370,7 @@ ext_test(struct ub_ctx* ctx, int argc, char** argv)
                inf[i].argc = argc;
                inf[i].argv = argv;
                inf[i].numq = 100;
+               inf[i].id_list = NULL;
                ub_thread_create(&inf[i].tid, ext_thread, &inf[i]);
        }
        /* the work happens here */
@@ -382,6 +378,16 @@ ext_test(struct ub_ctx* ctx, int argc, char** argv)
                ub_thread_join(inf[i].tid);
        }
        printf("extended test end\n");
+       /* free the id lists */
+       for(i=0; i<NUMTHR; i++) {
+               if(inf[i].id_list) {
+                       int j;
+                       for(j=0; j<inf->numq; j++) {
+                               lock_basic_destroy(&inf[i].id_list[j].lock);
+                       }
+                       free(inf[i].id_list);
+               }
+       }
        ub_ctx_delete(ctx);
        checklock_stop();
        return 0;
index 777ed7355ed770fe0ce37297b66d6728c1140668..0c1f3d077ebb274c44fcd49a52eadb26d8fc5545 100644 (file)
@@ -1195,6 +1195,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
        /* create packet with EDNS */
        pend->buffer = sldns_buffer_new(512);
        log_assert(pend->buffer);
+       log_assert(pend->buffer->_data);
        sldns_buffer_write_u16(pend->buffer, 0); /* id */
        sldns_buffer_write_u16(pend->buffer, flags);
        sldns_buffer_write_u16(pend->buffer, 1); /* qdcount */
index d11357c4acaa771dc6a12f4ab4e0980fd1bd1b57..e4d0d7944386e7f2e7abb545285e7703de1f5075 100644 (file)
@@ -532,6 +532,7 @@ qlist_add_line(struct perfinfo* info, char* line, int no)
                printf("error parsing query %d: %s\n", no, line);
                exit(1);
        }
+       log_assert(info->buf->_data);
        sldns_buffer_write_u16_at(info->buf, 0, (uint16_t)info->qlist_size); 
        if(info->qlist_size + 1 > info->qlist_capacity) {
                qlist_grow_capacity(info);
@@ -610,7 +611,7 @@ int main(int argc, char* argv[])
                case 'd':
                        if(atoi(optarg)==0 && strcmp(optarg, "0")!=0) {
                                printf("-d not a number %s", optarg);
-                               return 1;
+                               exit(1);
                        }
                        info.duration = atoi(optarg);
                        break;
@@ -635,11 +636,11 @@ int main(int argc, char* argv[])
        }
        if(!extstrtoaddr(argv[0], &info.dest, &info.destlen)) {
                printf("Could not parse ip: %s\n", argv[0]);
-               return 1;
+               exit(1);
        }
        if(info.qlist_size == 0) {
                printf("No queries to make, use -f or -a.\n");
-               return 1;
+               exit(1);
        }
        
        /* do the performance test */
index 12e0d8edbb68ff28e704d6f283c48145a92d3913..976c69e062e66b177a11b9b325bbaf9b21c5f672 100644 (file)
@@ -155,6 +155,7 @@ static void analyze(sldns_buffer* pkt)
 {
        uint16_t i, f, qd, an, ns, ar;
        int rrnum = 0;
+       log_assert(pkt && pkt->_data);
        printf("packet length %d\n", (int)sldns_buffer_limit(pkt));
        if(sldns_buffer_limit(pkt) < 12) return;
 
index 08d87470bd0067c63562a2fcaba54737cfc9a461..93a600425ca12d8a31a0abac3113a312242d654a 100644 (file)
@@ -458,6 +458,8 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
                if(parse_keyword(&parse, ";"))
                        continue; /* comment */
                if(parse_keyword(&parse, "SCENARIO_BEGIN")) {
+                       if(scen)
+                               fatal_exit("%d: double SCENARIO_BEGIN", *lineno);
                        scen = make_scenario(parse);
                        if(!scen)
                                fatal_exit("%d: could not make scen", *lineno);
@@ -801,14 +803,19 @@ macro_expand(rbtree_type* store, struct replay_runtime* runtime, char** text)
 
        /* check for functions */
        if(strcmp(buf, "time") == 0) {
-               snprintf(buf, sizeof(buf), ARG_LL "d", (long long)runtime->now_secs);
+               if(runtime)
+                       snprintf(buf, sizeof(buf), ARG_LL "d", (long long)runtime->now_secs);
+               else
+                       snprintf(buf, sizeof(buf), ARG_LL "d", (long long)0);
                *text += len;
                return strdup(buf);
        } else if(strcmp(buf, "timeout") == 0) {
                time_t res = 0;
-               struct fake_timer* t = first_timer(runtime);
-               if(t && (time_t)t->tv.tv_sec >= runtime->now_secs) 
-                       res = (time_t)t->tv.tv_sec - runtime->now_secs;
+               if(runtime) {
+                       struct fake_timer* t = first_timer(runtime);
+                       if(t && (time_t)t->tv.tv_sec >= runtime->now_secs) 
+                               res = (time_t)t->tv.tv_sec - runtime->now_secs;
+               }
                snprintf(buf, sizeof(buf), ARG_LL "d", (long long)res);
                *text += len;
                return strdup(buf);
index 4cd9b306c72e0a85f65d5f948f93f85a2bb40e6c..59c4e8dcc6435cb1872aea915fa07e1fbb7d254c 100644 (file)
@@ -118,6 +118,8 @@ static void get_random_data(char** fromp, char** top, char* zname)
        int labnum1[10], labnum2[10];
        int i;
        char* p;
+       memset(labnum1, 0, sizeof(int)*10);
+       memset(labnum2, 0, sizeof(int)*10);
 
        *fromp = buf1;
        *top = buf2;