aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-19 20:15:31 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-19 20:15:31 +0000
commitc9d068253d379fcbfc5102c3ca772d96f8bc2581 (patch)
tree34325a8cdb8a5ea0be2fd329c85560a5511001a0
parent1237387390f4be97f861a5cb93eec2445fe1a565 (diff)
downloadlibmicrohttpd-c9d068253d379fcbfc5102c3ca772d96f8bc2581.tar.gz
libmicrohttpd-c9d068253d379fcbfc5102c3ca772d96f8bc2581.zip
-fixing memory leaks in testcases
-rw-r--r--src/testcurl/test_post.c38
-rw-r--r--src/testcurl/test_postform.c35
-rw-r--r--src/testzzuf/test_post.c28
-rw-r--r--src/testzzuf/test_post_form.c31
4 files changed, 114 insertions, 18 deletions
diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c
index f889afd8..acc97e77 100644
--- a/src/testcurl/test_post.c
+++ b/src/testcurl/test_post.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file daemontest_post.c 22 * @file test_postx.c
23 * @brief Testcase for libmicrohttpd POST operations using URL-encoding 23 * @brief Testcase for libmicrohttpd POST operations using URL-encoding
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -47,6 +47,21 @@ struct CBC
47 size_t size; 47 size_t size;
48}; 48};
49 49
50
51static void
52completed_cb (void *cls,
53 struct MHD_Connection *connection,
54 void **con_cls,
55 enum MHD_RequestTerminationCode toe)
56{
57 struct MHD_PostProcessor *pp = *con_cls;
58
59 if (NULL != pp)
60 MHD_destroy_post_processor (pp);
61 *con_cls = NULL;
62}
63
64
50static size_t 65static size_t
51copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 66copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
52{ 67{
@@ -59,6 +74,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
59 return size * nmemb; 74 return size * nmemb;
60} 75}
61 76
77
62/** 78/**
63 * Note that this post_iterator is not perfect 79 * Note that this post_iterator is not perfect
64 * in that it fails to support incremental processing. 80 * in that it fails to support incremental processing.
@@ -140,7 +156,9 @@ testInternalPost ()
140 cbc.size = 2048; 156 cbc.size = 2048;
141 cbc.pos = 0; 157 cbc.pos = 0;
142 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 158 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
143 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 159 1080, NULL, NULL, &ahc_echo, NULL,
160 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
161 MHD_OPTION_END);
144 if (d == NULL) 162 if (d == NULL)
145 return 1; 163 return 1;
146 c = curl_easy_init (); 164 c = curl_easy_init ();
@@ -192,7 +210,9 @@ testMultithreadedPost ()
192 cbc.size = 2048; 210 cbc.size = 2048;
193 cbc.pos = 0; 211 cbc.pos = 0;
194 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 212 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
195 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 213 1081, NULL, NULL, &ahc_echo, NULL,
214 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
215 MHD_OPTION_END);
196 if (d == NULL) 216 if (d == NULL)
197 return 16; 217 return 16;
198 c = curl_easy_init (); 218 c = curl_easy_init ();
@@ -245,7 +265,9 @@ testMultithreadedPoolPost ()
245 cbc.pos = 0; 265 cbc.pos = 0;
246 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 266 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
247 1081, NULL, NULL, &ahc_echo, NULL, 267 1081, NULL, NULL, &ahc_echo, NULL,
248 MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); 268 MHD_OPTION_THREAD_POOL_SIZE, 4,
269 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
270 MHD_OPTION_END);
249 if (d == NULL) 271 if (d == NULL)
250 return 16; 272 return 16;
251 c = curl_easy_init (); 273 c = curl_easy_init ();
@@ -307,7 +329,9 @@ testExternalPost ()
307 cbc.size = 2048; 329 cbc.size = 2048;
308 cbc.pos = 0; 330 cbc.pos = 0;
309 d = MHD_start_daemon (MHD_USE_DEBUG, 331 d = MHD_start_daemon (MHD_USE_DEBUG,
310 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 332 1082, NULL, NULL, &ahc_echo, NULL,
333 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
334 MHD_OPTION_END);
311 if (d == NULL) 335 if (d == NULL)
312 return 256; 336 return 256;
313 c = curl_easy_init (); 337 c = curl_easy_init ();
@@ -507,7 +531,9 @@ testMultithreadedPostCancelPart(int flags)
507 cbc.size = 2048; 531 cbc.size = 2048;
508 cbc.pos = 0; 532 cbc.pos = 0;
509 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 533 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
510 1081, NULL, NULL, &ahc_cancel, NULL, MHD_OPTION_END); 534 1081, NULL, NULL, &ahc_cancel, NULL,
535 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
536 MHD_OPTION_END);
511 if (d == NULL) 537 if (d == NULL)
512 return 32768; 538 return 32768;
513 539
diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c
index c02cf636..3b63f840 100644
--- a/src/testcurl/test_postform.c
+++ b/src/testcurl/test_postform.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file daemontest_post.c 22 * @file test_postform.c
23 * @brief Testcase for libmicrohttpd POST operations using multipart/postform data 23 * @brief Testcase for libmicrohttpd POST operations using multipart/postform data
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -45,6 +45,21 @@ struct CBC
45 size_t size; 45 size_t size;
46}; 46};
47 47
48
49static void
50completed_cb (void *cls,
51 struct MHD_Connection *connection,
52 void **con_cls,
53 enum MHD_RequestTerminationCode toe)
54{
55 struct MHD_PostProcessor *pp = *con_cls;
56
57 if (NULL != pp)
58 MHD_destroy_post_processor (pp);
59 *con_cls = NULL;
60}
61
62
48static size_t 63static size_t
49copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 64copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
50{ 65{
@@ -57,6 +72,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
57 return size * nmemb; 72 return size * nmemb;
58} 73}
59 74
75
60/** 76/**
61 * Note that this post_iterator is not perfect 77 * Note that this post_iterator is not perfect
62 * in that it fails to support incremental processing. 78 * in that it fails to support incremental processing.
@@ -85,6 +101,7 @@ post_iterator (void *cls,
85 return MHD_YES; 101 return MHD_YES;
86} 102}
87 103
104
88static int 105static int
89ahc_echo (void *cls, 106ahc_echo (void *cls,
90 struct MHD_Connection *connection, 107 struct MHD_Connection *connection,
@@ -157,7 +174,9 @@ testInternalPost ()
157 cbc.size = 2048; 174 cbc.size = 2048;
158 cbc.pos = 0; 175 cbc.pos = 0;
159 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 176 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
160 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 177 1080, NULL, NULL, &ahc_echo, NULL,
178 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
179 MHD_OPTION_END);
161 if (d == NULL) 180 if (d == NULL)
162 return 1; 181 return 1;
163 c = curl_easy_init (); 182 c = curl_easy_init ();
@@ -211,7 +230,9 @@ testMultithreadedPost ()
211 cbc.size = 2048; 230 cbc.size = 2048;
212 cbc.pos = 0; 231 cbc.pos = 0;
213 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 232 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
214 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 233 1081, NULL, NULL, &ahc_echo, NULL,
234 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
235 MHD_OPTION_END);
215 if (d == NULL) 236 if (d == NULL)
216 return 16; 237 return 16;
217 c = curl_easy_init (); 238 c = curl_easy_init ();
@@ -266,7 +287,9 @@ testMultithreadedPoolPost ()
266 cbc.pos = 0; 287 cbc.pos = 0;
267 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 288 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
268 1081, NULL, NULL, &ahc_echo, NULL, 289 1081, NULL, NULL, &ahc_echo, NULL,
269 MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); 290 MHD_OPTION_THREAD_POOL_SIZE, 4,
291 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
292 MHD_OPTION_END);
270 if (d == NULL) 293 if (d == NULL)
271 return 16; 294 return 16;
272 c = curl_easy_init (); 295 c = curl_easy_init ();
@@ -330,7 +353,9 @@ testExternalPost ()
330 cbc.size = 2048; 353 cbc.size = 2048;
331 cbc.pos = 0; 354 cbc.pos = 0;
332 d = MHD_start_daemon (MHD_USE_DEBUG, 355 d = MHD_start_daemon (MHD_USE_DEBUG,
333 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 356 1082, NULL, NULL, &ahc_echo, NULL,
357 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
358 MHD_OPTION_END);
334 if (d == NULL) 359 if (d == NULL)
335 return 256; 360 return 256;
336 c = curl_easy_init (); 361 c = curl_easy_init ();
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
50 size_t size; 50 size_t size;
51}; 51};
52 52
53
54static void
55completed_cb (void *cls,
56 struct MHD_Connection *connection,
57 void **con_cls,
58 enum MHD_RequestTerminationCode toe)
59{
60 struct MHD_PostProcessor *pp = *con_cls;
61
62 if (NULL != pp)
63 MHD_destroy_post_processor (pp);
64 *con_cls = NULL;
65}
66
67
53static size_t 68static size_t
54copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 69copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
55{ 70{
@@ -62,6 +77,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
62 return size * nmemb; 77 return size * nmemb;
63} 78}
64 79
80
65/** 81/**
66 * Note that this post_iterator is not perfect 82 * Note that this post_iterator is not perfect
67 * in that it fails to support incremental processing. 83 * in that it fails to support incremental processing.
@@ -142,7 +158,9 @@ testInternalPost ()
142 cbc.size = 2048; 158 cbc.size = 2048;
143 cbc.pos = 0; 159 cbc.pos = 0;
144 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , 160 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
145 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 161 11080, NULL, NULL, &ahc_echo, NULL,
162 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
163 MHD_OPTION_END);
146 if (d == NULL) 164 if (d == NULL)
147 return 1; 165 return 1;
148 zzuf_socat_start (); 166 zzuf_socat_start ();
@@ -191,7 +209,9 @@ testMultithreadedPost ()
191 cbc.size = 2048; 209 cbc.size = 2048;
192 cbc.pos = 0; 210 cbc.pos = 0;
193 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , 211 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
194 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 212 11080, NULL, NULL, &ahc_echo, NULL,
213 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
214 MHD_OPTION_END);
195 if (d == NULL) 215 if (d == NULL)
196 return 16; 216 return 16;
197 217
@@ -252,7 +272,9 @@ testExternalPost ()
252 cbc.size = 2048; 272 cbc.size = 2048;
253 cbc.pos = 0; 273 cbc.pos = 0;
254 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , 274 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
255 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 275 1082, NULL, NULL, &ahc_echo, NULL,
276 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
277 MHD_OPTION_END);
256 if (d == NULL) 278 if (d == NULL)
257 return 256; 279 return 256;
258 multi = curl_multi_init (); 280 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 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file daemontest_post.c 22 * @file test_post_form.c
23 * @brief Testcase for libmicrohttpd POST operations using multipart/postform data 23 * @brief Testcase for libmicrohttpd POST operations using multipart/postform data
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -48,6 +48,21 @@ struct CBC
48 size_t size; 48 size_t size;
49}; 49};
50 50
51
52static void
53completed_cb (void *cls,
54 struct MHD_Connection *connection,
55 void **con_cls,
56 enum MHD_RequestTerminationCode toe)
57{
58 struct MHD_PostProcessor *pp = *con_cls;
59
60 if (NULL != pp)
61 MHD_destroy_post_processor (pp);
62 *con_cls = NULL;
63}
64
65
51static size_t 66static size_t
52copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 67copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
53{ 68{
@@ -90,6 +105,7 @@ post_iterator (void *cls,
90 return MHD_YES; 105 return MHD_YES;
91} 106}
92 107
108
93static int 109static int
94ahc_echo (void *cls, 110ahc_echo (void *cls,
95 struct MHD_Connection *connection, 111 struct MHD_Connection *connection,
@@ -161,7 +177,9 @@ testInternalPost ()
161 cbc.size = 2048; 177 cbc.size = 2048;
162 cbc.pos = 0; 178 cbc.pos = 0;
163 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , 179 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
164 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 180 11080, NULL, NULL, &ahc_echo, NULL,
181 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
182 MHD_OPTION_END);
165 if (d == NULL) 183 if (d == NULL)
166 return 1; 184 return 1;
167 zzuf_socat_start (); 185 zzuf_socat_start ();
@@ -195,6 +213,7 @@ testInternalPost ()
195 return 0; 213 return 0;
196} 214}
197 215
216
198static int 217static int
199testMultithreadedPost () 218testMultithreadedPost ()
200{ 219{
@@ -209,7 +228,9 @@ testMultithreadedPost ()
209 cbc.size = 2048; 228 cbc.size = 2048;
210 cbc.pos = 0; 229 cbc.pos = 0;
211 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , 230 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
212 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 231 11080, NULL, NULL, &ahc_echo, NULL,
232 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
233 MHD_OPTION_END);
213 if (d == NULL) 234 if (d == NULL)
214 return 16; 235 return 16;
215 zzuf_socat_start (); 236 zzuf_socat_start ();
@@ -268,7 +289,9 @@ testExternalPost ()
268 cbc.size = 2048; 289 cbc.size = 2048;
269 cbc.pos = 0; 290 cbc.pos = 0;
270 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , 291 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
271 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 292 1082, NULL, NULL, &ahc_echo, NULL,
293 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
294 MHD_OPTION_END);
272 if (d == NULL) 295 if (d == NULL)
273 return 256; 296 return 256;
274 multi = curl_multi_init (); 297 multi = curl_multi_init ();