libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit c9d068253d379fcbfc5102c3ca772d96f8bc2581
parent 1237387390f4be97f861a5cb93eec2445fe1a565
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 19 Jul 2013 20:15:31 +0000

-fixing memory leaks in testcases

Diffstat:
Msrc/testcurl/test_post.c | 38++++++++++++++++++++++++++++++++------
Msrc/testcurl/test_postform.c | 35++++++++++++++++++++++++++++++-----
Msrc/testzzuf/test_post.c | 28+++++++++++++++++++++++++---
Msrc/testzzuf/test_post_form.c | 31+++++++++++++++++++++++++++----
4 files changed, 114 insertions(+), 18 deletions(-)

diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c @@ -19,7 +19,7 @@ */ /** - * @file daemontest_post.c + * @file test_postx.c * @brief Testcase for libmicrohttpd POST operations using URL-encoding * @author Christian Grothoff */ @@ -47,6 +47,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) { @@ -59,6 +74,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. @@ -140,7 +156,9 @@ testInternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, - 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 1; c = curl_easy_init (); @@ -192,7 +210,9 @@ testMultithreadedPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, - 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1081, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); @@ -245,7 +265,9 @@ testMultithreadedPoolPost () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); @@ -307,7 +329,9 @@ testExternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (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; c = curl_easy_init (); @@ -507,7 +531,9 @@ testMultithreadedPostCancelPart(int flags) cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, - 1081, NULL, NULL, &ahc_cancel, NULL, MHD_OPTION_END); + 1081, NULL, NULL, &ahc_cancel, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 32768; diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c @@ -19,7 +19,7 @@ */ /** - * @file daemontest_post.c + * @file test_postform.c * @brief Testcase for libmicrohttpd POST operations using multipart/postform data * @author Christian Grothoff */ @@ -45,6 +45,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) { @@ -57,6 +72,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. @@ -85,6 +101,7 @@ post_iterator (void *cls, return MHD_YES; } + static int ahc_echo (void *cls, struct MHD_Connection *connection, @@ -157,7 +174,9 @@ testInternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, - 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1080, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 1; c = curl_easy_init (); @@ -211,7 +230,9 @@ testMultithreadedPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, - 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); + 1081, NULL, NULL, &ahc_echo, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); @@ -266,7 +287,9 @@ testMultithreadedPoolPost () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, + MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); @@ -330,7 +353,9 @@ testExternalPost () cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (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; c = curl_easy_init (); diff --git 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 @@ -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 ();