1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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 https://curl.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 * This source code is used for lib1502, lib1503, lib1504 and lib1505 with
24 * only #ifdefs controlling the cleanup sequence.
26 * Test case 1502 converted from bug report #3575448, identifying a memory
27 * leak in the CURLOPT_RESOLVE handling with the multi interface.
38 #define TEST_HANG_TIMEOUT 60 * 1000
49 /* DNS cache injection */
50 struct curl_slist *dns_cache_list;
52 snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
57 dns_cache_list = curl_slist_append(NULL, redirect);
59 fprintf(stderr, "curl_slist_append() failed\n");
60 return TEST_ERR_MAJOR_BAD;
63 res_global_init(CURL_GLOBAL_ALL);
65 curl_slist_free_all(dns_cache_list);
71 easy_setopt(easy, CURLOPT_URL, URL);
72 easy_setopt(easy, CURLOPT_HEADER, 1L);
73 easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list);
77 multi_add_handle(multi, easy);
79 multi_perform(multi, &still_running);
81 abort_on_test_timeout();
83 while(still_running) {
84 struct timeval timeout;
96 multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
98 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
100 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
102 abort_on_test_timeout();
104 multi_perform(multi, &still_running);
106 abort_on_test_timeout();
112 /* undocumented cleanup sequence - type UA */
113 curl_multi_cleanup(multi);
114 curl_easy_cleanup(easy);
115 curl_global_cleanup();
119 /* proper cleanup sequence - type PA */
120 curl_multi_remove_handle(multi, easy);
121 curl_multi_cleanup(multi);
122 curl_easy_cleanup(easy);
123 curl_global_cleanup();
127 /* undocumented cleanup sequence - type UB */
128 curl_easy_cleanup(easy);
129 curl_multi_cleanup(multi);
130 curl_global_cleanup();
134 /* proper cleanup sequence - type PB */
135 curl_multi_remove_handle(multi, easy);
136 curl_easy_cleanup(easy);
137 curl_multi_cleanup(multi);
138 curl_global_cleanup();
141 curl_slist_free_all(dns_cache_list);