From c9d068253d379fcbfc5102c3ca772d96f8bc2581 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 19 Jul 2013 20:15:31 +0000 Subject: -fixing memory leaks in testcases --- src/testzzuf/test_post.c | 28 +++++++++++++++++++++++++--- src/testzzuf/test_post_form.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 7 deletions(-) (limited to 'src/testzzuf') diff --git a/src/testzzuf/test_post.c b/src/testzzuf/test_post.c index 66077b4f..9bc3c604 100644 --- a/src/testzzuf/test_post.c +++ b/src/testzzuf/test_post.c @@ -50,6 +50,21 @@ struct CBC size_t size; }; + +static void +completed_cb (void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe) +{ + struct MHD_PostProcessor *pp = *con_cls; + + if (NULL != pp) + MHD_destroy_post_processor (pp); + *con_cls = NULL; +} + + static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) { @@ -62,6 +77,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) return size * nmemb; } + /** * Note that this post_iterator is not perfect * in that it fails to support incremental processing. @@ -142,7 +158,9 @@ testInternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , - 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 11080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 1; zzuf_socat_start (); @@ -191,7 +209,9 @@ testMultithreadedPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , - 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 11080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; @@ -252,7 +272,9 @@ testExternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , - 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1082, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 256; multi = curl_multi_init (); diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c index 873c7fef..34bc0114 100644 --- a/src/testzzuf/test_post_form.c +++ b/src/testzzuf/test_post_form.c @@ -19,7 +19,7 @@ */ /** - * @file daemontest_post.c + * @file test_post_form.c * @brief Testcase for libmicrohttpd POST operations using multipart/postform data * @author Christian Grothoff */ @@ -48,6 +48,21 @@ struct CBC size_t size; }; + +static void +completed_cb (void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe) +{ + struct MHD_PostProcessor *pp = *con_cls; + + if (NULL != pp) + MHD_destroy_post_processor (pp); + *con_cls = NULL; +} + + static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) { @@ -90,6 +105,7 @@ post_iterator (void *cls, return MHD_YES; } + static int ahc_echo (void *cls, struct MHD_Connection *connection, @@ -161,7 +177,9 @@ testInternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , - 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 11080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 1; zzuf_socat_start (); @@ -195,6 +213,7 @@ testInternalPost () return 0; } + static int testMultithreadedPost () { @@ -209,7 +228,9 @@ testMultithreadedPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , - 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 11080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; zzuf_socat_start (); @@ -268,7 +289,9 @@ testExternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , - 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1082, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 256; multi = curl_multi_init (); -- cgit v1.2.3