- 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.


git-svn-id: file:///svn/unbound/trunk@4897 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2018-09-13 09:45:07 +00:00
parent 9a82526b91
commit fe8b22caa1
7 changed files with 36 additions and 15 deletions

View file

@ -4,6 +4,9 @@
- free memory leaks in config strlist and str2list insert functions. - free memory leaks in config strlist and str2list insert functions.
- do not move unused argv variable after getopt. - do not move unused argv variable after getopt.
- Remove unused if clause in testcode. - 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 11 September 2018: Wouter
- Fixed unused return value warnings in contrib/fastrpz.patch for - Fixed unused return value warnings in contrib/fastrpz.patch for

View file

@ -182,6 +182,8 @@ struct ext_thr_info {
char** argv; char** argv;
/** number of queries to do */ /** number of queries to do */
int numq; 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 */ /** 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++) { for(i=0; i<inf->numq; i++) {
lock_basic_init(&async_ids[i].lock); lock_basic_init(&async_ids[i].lock);
} }
inf->id_list = async_ids;
} }
for(i=0; i<inf->numq; i++) { for(i=0; i<inf->numq; i++) {
if(async_ids) { if(async_ids) {
@ -347,14 +350,6 @@ ext_thread(void* arg)
/* if these locks are destroyed, or if the async_ids is freed, then /* if these locks are destroyed, or if the async_ids is freed, then
a use-after-free happens in another thread. a use-after-free happens in another thread.
The allocation is only part of this test, though. */ 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; return NULL;
} }
@ -375,6 +370,7 @@ ext_test(struct ub_ctx* ctx, int argc, char** argv)
inf[i].argc = argc; inf[i].argc = argc;
inf[i].argv = argv; inf[i].argv = argv;
inf[i].numq = 100; inf[i].numq = 100;
inf[i].id_list = NULL;
ub_thread_create(&inf[i].tid, ext_thread, &inf[i]); ub_thread_create(&inf[i].tid, ext_thread, &inf[i]);
} }
/* the work happens here */ /* the work happens here */
@ -382,6 +378,16 @@ ext_test(struct ub_ctx* ctx, int argc, char** argv)
ub_thread_join(inf[i].tid); ub_thread_join(inf[i].tid);
} }
printf("extended test end\n"); 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); ub_ctx_delete(ctx);
checklock_stop(); checklock_stop();
return 0; return 0;

View file

@ -1195,6 +1195,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
/* create packet with EDNS */ /* create packet with EDNS */
pend->buffer = sldns_buffer_new(512); pend->buffer = sldns_buffer_new(512);
log_assert(pend->buffer); log_assert(pend->buffer);
log_assert(pend->buffer->_data);
sldns_buffer_write_u16(pend->buffer, 0); /* id */ sldns_buffer_write_u16(pend->buffer, 0); /* id */
sldns_buffer_write_u16(pend->buffer, flags); sldns_buffer_write_u16(pend->buffer, flags);
sldns_buffer_write_u16(pend->buffer, 1); /* qdcount */ sldns_buffer_write_u16(pend->buffer, 1); /* qdcount */

View file

@ -532,6 +532,7 @@ qlist_add_line(struct perfinfo* info, char* line, int no)
printf("error parsing query %d: %s\n", no, line); printf("error parsing query %d: %s\n", no, line);
exit(1); exit(1);
} }
log_assert(info->buf->_data);
sldns_buffer_write_u16_at(info->buf, 0, (uint16_t)info->qlist_size); sldns_buffer_write_u16_at(info->buf, 0, (uint16_t)info->qlist_size);
if(info->qlist_size + 1 > info->qlist_capacity) { if(info->qlist_size + 1 > info->qlist_capacity) {
qlist_grow_capacity(info); qlist_grow_capacity(info);
@ -610,7 +611,7 @@ int main(int argc, char* argv[])
case 'd': case 'd':
if(atoi(optarg)==0 && strcmp(optarg, "0")!=0) { if(atoi(optarg)==0 && strcmp(optarg, "0")!=0) {
printf("-d not a number %s", optarg); printf("-d not a number %s", optarg);
return 1; exit(1);
} }
info.duration = atoi(optarg); info.duration = atoi(optarg);
break; break;
@ -635,11 +636,11 @@ int main(int argc, char* argv[])
} }
if(!extstrtoaddr(argv[0], &info.dest, &info.destlen)) { if(!extstrtoaddr(argv[0], &info.dest, &info.destlen)) {
printf("Could not parse ip: %s\n", argv[0]); printf("Could not parse ip: %s\n", argv[0]);
return 1; exit(1);
} }
if(info.qlist_size == 0) { if(info.qlist_size == 0) {
printf("No queries to make, use -f or -a.\n"); printf("No queries to make, use -f or -a.\n");
return 1; exit(1);
} }
/* do the performance test */ /* do the performance test */

View file

@ -155,6 +155,7 @@ static void analyze(sldns_buffer* pkt)
{ {
uint16_t i, f, qd, an, ns, ar; uint16_t i, f, qd, an, ns, ar;
int rrnum = 0; int rrnum = 0;
log_assert(pkt && pkt->_data);
printf("packet length %d\n", (int)sldns_buffer_limit(pkt)); printf("packet length %d\n", (int)sldns_buffer_limit(pkt));
if(sldns_buffer_limit(pkt) < 12) return; if(sldns_buffer_limit(pkt) < 12) return;

View file

@ -458,6 +458,8 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
if(parse_keyword(&parse, ";")) if(parse_keyword(&parse, ";"))
continue; /* comment */ continue; /* comment */
if(parse_keyword(&parse, "SCENARIO_BEGIN")) { if(parse_keyword(&parse, "SCENARIO_BEGIN")) {
if(scen)
fatal_exit("%d: double SCENARIO_BEGIN", *lineno);
scen = make_scenario(parse); scen = make_scenario(parse);
if(!scen) if(!scen)
fatal_exit("%d: could not make scen", *lineno); 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 */ /* check for functions */
if(strcmp(buf, "time") == 0) { if(strcmp(buf, "time") == 0) {
if(runtime)
snprintf(buf, sizeof(buf), ARG_LL "d", (long long)runtime->now_secs); 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; *text += len;
return strdup(buf); return strdup(buf);
} else if(strcmp(buf, "timeout") == 0) { } else if(strcmp(buf, "timeout") == 0) {
time_t res = 0; time_t res = 0;
if(runtime) {
struct fake_timer* t = first_timer(runtime); struct fake_timer* t = first_timer(runtime);
if(t && (time_t)t->tv.tv_sec >= runtime->now_secs) if(t && (time_t)t->tv.tv_sec >= runtime->now_secs)
res = (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); snprintf(buf, sizeof(buf), ARG_LL "d", (long long)res);
*text += len; *text += len;
return strdup(buf); return strdup(buf);

View file

@ -118,6 +118,8 @@ static void get_random_data(char** fromp, char** top, char* zname)
int labnum1[10], labnum2[10]; int labnum1[10], labnum2[10];
int i; int i;
char* p; char* p;
memset(labnum1, 0, sizeof(int)*10);
memset(labnum2, 0, sizeof(int)*10);
*fromp = buf1; *fromp = buf1;
*top = buf2; *top = buf2;