From 1a9b1a0ad3e1e98a307c8a99211ebc3a94b4ac3e Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 29 Dec 2019 10:12:23 -0800 Subject: fixes #1065 resolver leaks work structures This includes changes to support setting the sanitizer *correctly* (the old code CMake stuff didn't quite get it right), and addresses a number of failures in the test code found by the address sanitizer. --- tests/httpserver.c | 15 ++++++++++++++- tests/ipcsupp.c | 3 ++- tests/message.c | 5 +++-- tests/sock.c | 1 + tests/tcpsupp.c | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/httpserver.c b/tests/httpserver.c index 996d20b4..a69889a5 100644 --- a/tests/httpserver.c +++ b/tests/httpserver.c @@ -353,7 +353,7 @@ TestMain("HTTP Server", { So(size == strlen(doc1)); So(memcmp(data, doc1, size) == 0); So(strcmp(ctype, "text/html") == 0); - free(ctype); + nng_strfree(ctype); nng_free(data, size); }); @@ -403,6 +403,8 @@ TestMain("HTTP Server", { snprintf(fullurl, sizeof(fullurl), "%s/docs/", urlstr); So(httpget(fullurl, &data, &size, &stat, &ctype) == 0); So(stat == NNG_HTTP_STATUS_NOT_FOUND); + nng_strfree(ctype); + nng_free(data, size); }); Convey("Custom error page works", { @@ -418,6 +420,8 @@ TestMain("HTTP Server", { So(stat == NNG_HTTP_STATUS_NOT_FOUND); So(size == strlen(doc4)); So(memcmp(data, doc4, size) == 0); + nng_strfree(ctype); + nng_free(data, size); }); Convey("Bad method gives 405", { @@ -440,6 +444,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); Convey("Version 0.9 gives 505", { char fullurl[256]; @@ -461,6 +466,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); Convey("Missing Host gives 400", { char fullurl[256]; @@ -482,6 +488,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); }); @@ -529,6 +536,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(rxdata, size); }); Convey("Get method gives 405", { @@ -551,6 +559,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); }); @@ -598,6 +607,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); Convey("Tree redirect works", { @@ -633,6 +643,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); Convey("POST Redirect works", { @@ -667,6 +678,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(data, size); }); }); @@ -714,6 +726,7 @@ TestMain("HTTP Server", { nng_http_req_free(req); nng_http_res_free(res); nng_url_free(curl); + nng_free(rxdata, size); }); }); }); diff --git a/tests/ipcsupp.c b/tests/ipcsupp.c index bb7d92f7..d5128098 100644 --- a/tests/ipcsupp.c +++ b/tests/ipcsupp.c @@ -51,7 +51,8 @@ TestMain("Supplemental IPC", { Reset({ nng_aio_free(daio); - nng_aio_free(laio); + nng_aio_free(laio); + nng_aio_free(maio); if (c1 != NULL) { nng_stream_close(c1); nng_stream_free(c1); diff --git a/tests/message.c b/tests/message.c index cc50f542..4dfc9921 100644 --- a/tests/message.c +++ b/tests/message.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2019 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -187,11 +187,12 @@ TestMain("Message Tests", { }); Convey("Message dup copies pipe", { - nng_pipe p = NNG_PIPE_INITIALIZER; + nng_pipe p = NNG_PIPE_INITIALIZER; nng_msg *m2; memset(&p, 0x22, sizeof(p)); nng_msg_set_pipe(msg, p); So(nng_msg_dup(&m2, msg) == 0); + Reset({ nng_msg_free(m2); }); p = nng_msg_get_pipe(m2); So(nng_pipe_id(p) == 0x22222222); }); diff --git a/tests/sock.c b/tests/sock.c index cf3cc705..b6b981c8 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -82,6 +82,7 @@ test_send_nonblock(void) TEST_CHECK(nng_sendmsg(s1, msg, NNG_FLAG_NONBLOCK) == NNG_EAGAIN); TEST_CHECK(testutil_clock() < (now + 100)); TEST_CHECK(nng_close(s1) == 0); + nng_msg_free(msg); } void diff --git a/tests/tcpsupp.c b/tests/tcpsupp.c index e25383c5..39558f58 100644 --- a/tests/tcpsupp.c +++ b/tests/tcpsupp.c @@ -66,6 +66,7 @@ TestMain("Supplemental TCP", { Reset({ nng_aio_free(daio); nng_aio_free(laio); + nng_aio_free(maio); if (c1 != NULL) { nng_stream_close(c1); nng_stream_free(c1); -- cgit v1.2.3-70-g09d2