Fix resource leaks in the unit tests; found by coverity

This commit is contained in:
Nick Mathewson 2012-07-26 09:53:20 -04:00
parent 4f3732d75e
commit 270f279fb5
2 changed files with 13 additions and 6 deletions

View File

@ -2660,9 +2660,11 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL)
goto out;
/* 13 chars */
if (strcmp(header, "d"))
if (strcmp(header, "d")) {
free((void*)header);
goto out;
free((char*)header);
}
free((void*)header);
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 13),
"This is funny", 13))
@ -2688,8 +2690,10 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL)
goto out;
/* 8 chars */
if (strcmp(header, "8"))
if (strcmp(header, "8")) {
free((void*)header);
goto out;
}
free((char *)header);
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 8),
@ -2702,9 +2706,11 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL)
goto out;
/* 0 chars */
if (strcmp(header, "0"))
if (strcmp(header, "0")) {
free((void*)header);
goto out;
free((char *)header);
}
free((void *)header);
test_ok = 2;

View File

@ -102,7 +102,7 @@ regress_get_dnsserver(struct event_base *base,
struct sockaddr_in my_addr;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock <= 0) {
if (sock < 0) {
tt_abort_perror("socket");
}
@ -113,6 +113,7 @@ regress_get_dnsserver(struct event_base *base,
my_addr.sin_port = htons(*portnum);
my_addr.sin_addr.s_addr = htonl(0x7f000001UL);
if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) {
evutil_closesocket(sock);
tt_abort_perror("bind");
}
port = evdns_add_server_port_with_base(base, sock, 0, cb, arg);