diff --git a/doc/Changelog b/doc/Changelog index 7cbc6ab26..95b3cfb65 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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 diff --git a/testcode/asynclook.c b/testcode/asynclook.c index 06bcf5ab8..9a74dbb84 100644 --- a/testcode/asynclook.c +++ b/testcode/asynclook.c @@ -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; inumq; i++) { lock_basic_init(&async_ids[i].lock); } + inf->id_list = async_ids; } for(i=0; inumq; 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; inumq; 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; inumq; j++) { + lock_basic_destroy(&inf[i].id_list[j].lock); + } + free(inf[i].id_list); + } + } ub_ctx_delete(ctx); checklock_stop(); return 0; diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 777ed7355..0c1f3d077 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -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 */ diff --git a/testcode/perf.c b/testcode/perf.c index d11357c4a..e4d0d7944 100644 --- a/testcode/perf.c +++ b/testcode/perf.c @@ -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 */ diff --git a/testcode/pktview.c b/testcode/pktview.c index 12e0d8edb..976c69e06 100644 --- a/testcode/pktview.c +++ b/testcode/pktview.c @@ -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; diff --git a/testcode/replay.c b/testcode/replay.c index 08d87470b..93a600425 100644 --- a/testcode/replay.c +++ b/testcode/replay.c @@ -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); diff --git a/testcode/unitneg.c b/testcode/unitneg.c index 4cd9b306c..59c4e8dcc 100644 --- a/testcode/unitneg.c +++ b/testcode/unitneg.c @@ -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;