• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 https://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 
30 #include "test.h"
31 
32 #include <limits.h>
33 
34 #include "testutil.h"
35 #include "warnless.h"
36 #include "memdebug.h"
37 
38 #define TEST_HANG_TIMEOUT 60 * 1000
39 
test(char * URL)40 int test(char *URL)
41 {
42   CURL *easy = NULL;
43   CURLM *multi = NULL;
44   int still_running;
45   int res = 0;
46 
47   char redirect[160];
48 
49   /* DNS cache injection */
50   struct curl_slist *dns_cache_list;
51 
52   snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
53            libtest_arg3);
54 
55   start_test_timing();
56 
57   dns_cache_list = curl_slist_append(NULL, redirect);
58   if(!dns_cache_list) {
59     fprintf(stderr, "curl_slist_append() failed\n");
60     return TEST_ERR_MAJOR_BAD;
61   }
62 
63   res_global_init(CURL_GLOBAL_ALL);
64   if(res) {
65     curl_slist_free_all(dns_cache_list);
66     return res;
67   }
68 
69   easy_init(easy);
70 
71   easy_setopt(easy, CURLOPT_URL, URL);
72   easy_setopt(easy, CURLOPT_HEADER, 1L);
73   easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list);
74 
75   multi_init(multi);
76 
77   multi_add_handle(multi, easy);
78 
79   multi_perform(multi, &still_running);
80 
81   abort_on_test_timeout();
82 
83   while(still_running) {
84     struct timeval timeout;
85     fd_set fdread;
86     fd_set fdwrite;
87     fd_set fdexcep;
88     int maxfd = -99;
89 
90     FD_ZERO(&fdread);
91     FD_ZERO(&fdwrite);
92     FD_ZERO(&fdexcep);
93     timeout.tv_sec = 1;
94     timeout.tv_usec = 0;
95 
96     multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
97 
98     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
99 
100     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
101 
102     abort_on_test_timeout();
103 
104     multi_perform(multi, &still_running);
105 
106     abort_on_test_timeout();
107   }
108 
109 test_cleanup:
110 
111 #ifdef LIB1502
112   /* undocumented cleanup sequence - type UA */
113   curl_multi_cleanup(multi);
114   curl_easy_cleanup(easy);
115   curl_global_cleanup();
116 #endif
117 
118 #ifdef LIB1503
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();
124 #endif
125 
126 #ifdef LIB1504
127   /* undocumented cleanup sequence - type UB */
128   curl_easy_cleanup(easy);
129   curl_multi_cleanup(multi);
130   curl_global_cleanup();
131 #endif
132 
133 #ifdef LIB1505
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();
139 #endif
140 
141   curl_slist_free_all(dns_cache_list);
142 
143   return res;
144 }
145