lib1502.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /*
  23. * This source code is used for lib1502, lib1503, lib1504 and lib1505 with
  24. * only #ifdefs controlling the cleanup sequence.
  25. *
  26. * Test case 1502 converted from bug report #3575448, identifying a memory
  27. * leak in the CURLOPT_RESOLVE handling with the multi interface.
  28. */
  29. #include "test.h"
  30. #ifdef HAVE_LIMITS_H
  31. #include <limits.h>
  32. #endif
  33. #include "testutil.h"
  34. #include "warnless.h"
  35. #include "memdebug.h"
  36. #define TEST_HANG_TIMEOUT 60 * 1000
  37. int test(char *URL)
  38. {
  39. CURL* easy = NULL;
  40. CURLM* multi = NULL;
  41. int still_running;
  42. int res = 0;
  43. char redirect[160];
  44. /* DNS cache injection */
  45. struct curl_slist *dns_cache_list;
  46. sprintf(redirect, "google.com:%s:%s", libtest_arg2, libtest_arg3);
  47. start_test_timing();
  48. dns_cache_list = curl_slist_append(NULL, redirect);
  49. if(!dns_cache_list) {
  50. fprintf(stderr, "curl_slist_append() failed\n");
  51. return TEST_ERR_MAJOR_BAD;
  52. }
  53. res_global_init(CURL_GLOBAL_ALL);
  54. if(res) {
  55. curl_slist_free_all(dns_cache_list);
  56. return res;
  57. }
  58. easy_init(easy);
  59. easy_setopt(easy, CURLOPT_URL, URL);
  60. easy_setopt(easy, CURLOPT_HEADER, 1L);
  61. easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list);
  62. multi_init(multi);
  63. multi_add_handle(multi, easy);
  64. multi_perform(multi, &still_running);
  65. abort_on_test_timeout();
  66. while(still_running) {
  67. struct timeval timeout;
  68. fd_set fdread;
  69. fd_set fdwrite;
  70. fd_set fdexcep;
  71. int maxfd = -99;
  72. FD_ZERO(&fdread);
  73. FD_ZERO(&fdwrite);
  74. FD_ZERO(&fdexcep);
  75. timeout.tv_sec = 1;
  76. timeout.tv_usec = 0;
  77. multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  78. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  79. select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
  80. abort_on_test_timeout();
  81. multi_perform(multi, &still_running);
  82. abort_on_test_timeout();
  83. }
  84. test_cleanup:
  85. #ifdef LIB1502
  86. /* undocumented cleanup sequence - type UA */
  87. curl_multi_cleanup(multi);
  88. curl_easy_cleanup(easy);
  89. curl_global_cleanup();
  90. #endif
  91. #ifdef LIB1503
  92. /* proper cleanup sequence - type PA */
  93. curl_multi_remove_handle(multi, easy);
  94. curl_multi_cleanup(multi);
  95. curl_easy_cleanup(easy);
  96. curl_global_cleanup();
  97. #endif
  98. #ifdef LIB1504
  99. /* undocumented cleanup sequence - type UB */
  100. curl_easy_cleanup(easy);
  101. curl_multi_cleanup(multi);
  102. curl_global_cleanup();
  103. #endif
  104. #ifdef LIB1505
  105. /* proper cleanup sequence - type PB */
  106. curl_multi_remove_handle(multi, easy);
  107. curl_easy_cleanup(easy);
  108. curl_multi_cleanup(multi);
  109. curl_global_cleanup();
  110. #endif
  111. curl_slist_free_all(dns_cache_list);
  112. return res;
  113. }