diff options
Diffstat (limited to 'src/examples/post_example.c')
-rw-r--r-- | src/examples/post_example.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/examples/post_example.c b/src/examples/post_example.c index 8b92956d..6c9a3f4b 100644 --- a/src/examples/post_example.c +++ b/src/examples/post_example.c | |||
@@ -313,23 +313,28 @@ fill_v1_form (const void *cls, | |||
313 | struct MHD_Connection *connection) | 313 | struct MHD_Connection *connection) |
314 | { | 314 | { |
315 | int ret; | 315 | int ret; |
316 | size_t slen; | ||
316 | char *reply; | 317 | char *reply; |
317 | struct MHD_Response *response; | 318 | struct MHD_Response *response; |
318 | (void)cls; /* Unused. Silent compiler warning. */ | 319 | (void)cls; /* Unused. Silent compiler warning. */ |
319 | 320 | ||
320 | reply = malloc (strlen (MAIN_PAGE) + strlen (session->value_1) + 1); | 321 | slen = strlen (MAIN_PAGE) + strlen (session->value_1); |
322 | reply = malloc (slen + 1); | ||
321 | if (NULL == reply) | 323 | if (NULL == reply) |
322 | return MHD_NO; | 324 | return MHD_NO; |
323 | snprintf (reply, | 325 | snprintf (reply, |
324 | strlen (MAIN_PAGE) + strlen (session->value_1) + 1, | 326 | slen + 1, |
325 | MAIN_PAGE, | 327 | MAIN_PAGE, |
326 | session->value_1); | 328 | session->value_1); |
327 | /* return static form */ | 329 | /* return static form */ |
328 | response = MHD_create_response_from_buffer (strlen (reply), | 330 | response = MHD_create_response_from_buffer (slen, |
329 | (void *) reply, | 331 | (void *) reply, |
330 | MHD_RESPMEM_MUST_FREE); | 332 | MHD_RESPMEM_MUST_FREE); |
331 | if (NULL == response) | 333 | if (NULL == response) |
334 | { | ||
335 | free (reply); | ||
332 | return MHD_NO; | 336 | return MHD_NO; |
337 | } | ||
333 | add_session_cookie (session, response); | 338 | add_session_cookie (session, response); |
334 | MHD_add_response_header (response, | 339 | MHD_add_response_header (response, |
335 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 340 | MHD_HTTP_HEADER_CONTENT_ENCODING, |
@@ -359,22 +364,27 @@ fill_v1_v2_form (const void *cls, | |||
359 | int ret; | 364 | int ret; |
360 | char *reply; | 365 | char *reply; |
361 | struct MHD_Response *response; | 366 | struct MHD_Response *response; |
367 | size_t slen; | ||
362 | (void)cls; /* Unused. Silent compiler warning. */ | 368 | (void)cls; /* Unused. Silent compiler warning. */ |
363 | 369 | ||
364 | reply = malloc (strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2) + 1); | 370 | slen = strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2); |
371 | reply = malloc (slen + 1); | ||
365 | if (NULL == reply) | 372 | if (NULL == reply) |
366 | return MHD_NO; | 373 | return MHD_NO; |
367 | snprintf (reply, | 374 | snprintf (reply, |
368 | strlen (SECOND_PAGE) + strlen (session->value_1) + strlen (session->value_2) + 1, | 375 | slen + 1, |
369 | SECOND_PAGE, | 376 | SECOND_PAGE, |
370 | session->value_1, | 377 | session->value_1, |
371 | session->value_2); | 378 | session->value_2); |
372 | /* return static form */ | 379 | /* return static form */ |
373 | response = MHD_create_response_from_buffer (strlen (reply), | 380 | response = MHD_create_response_from_buffer (slen, |
374 | (void *) reply, | 381 | (void *) reply, |
375 | MHD_RESPMEM_MUST_FREE); | 382 | MHD_RESPMEM_MUST_FREE); |
376 | if (NULL == response) | 383 | if (NULL == response) |
384 | { | ||
385 | free (reply); | ||
377 | return MHD_NO; | 386 | return MHD_NO; |
387 | } | ||
378 | add_session_cookie (session, response); | 388 | add_session_cookie (session, response); |
379 | MHD_add_response_header (response, | 389 | MHD_add_response_header (response, |
380 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 390 | MHD_HTTP_HEADER_CONTENT_ENCODING, |