lib1502.c
Go to the documentation of this file.
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 #ifdef HAVE_LIMITS_H
33 #include <limits.h>
34 #endif
35 
36 #include "testutil.h"
37 #include "warnless.h"
38 #include "memdebug.h"
39 
40 #define TEST_HANG_TIMEOUT 60 * 1000
41 
42 int test(char *URL)
43 {
44  CURL *easy = NULL;
45  CURLM *multi = NULL;
46  int still_running;
47  int res = 0;
48 
49  char redirect[160];
50 
51  /* DNS cache injection */
52  struct curl_slist *dns_cache_list;
53 
54  snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
55  libtest_arg3);
56 
58 
59  dns_cache_list = curl_slist_append(NULL, redirect);
60  if(!dns_cache_list) {
61  fprintf(stderr, "curl_slist_append() failed\n");
62  return TEST_ERR_MAJOR_BAD;
63  }
64 
66  if(res) {
67  curl_slist_free_all(dns_cache_list);
68  return res;
69  }
70 
71  easy_init(easy);
72 
73  easy_setopt(easy, CURLOPT_URL, URL);
74  easy_setopt(easy, CURLOPT_HEADER, 1L);
75  easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list);
76 
77  multi_init(multi);
78 
79  multi_add_handle(multi, easy);
80 
81  multi_perform(multi, &still_running);
82 
84 
85  while(still_running) {
86  struct timeval timeout;
87  fd_set fdread;
88  fd_set fdwrite;
89  fd_set fdexcep;
90  int maxfd = -99;
91 
92  FD_ZERO(&fdread);
93  FD_ZERO(&fdwrite);
94  FD_ZERO(&fdexcep);
95  timeout.tv_sec = 1;
96  timeout.tv_usec = 0;
97 
98  multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
99 
100  /* At this point, maxfd is guaranteed to be greater or equal than -1. */
101 
102  select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
103 
105 
106  multi_perform(multi, &still_running);
107 
109  }
110 
111 test_cleanup:
112 
113 #ifdef LIB1502
114  /* undocumented cleanup sequence - type UA */
115  curl_multi_cleanup(multi);
116  curl_easy_cleanup(easy);
118 #endif
119 
120 #ifdef LIB1503
121  /* proper cleanup sequence - type PA */
122  curl_multi_remove_handle(multi, easy);
123  curl_multi_cleanup(multi);
124  curl_easy_cleanup(easy);
126 #endif
127 
128 #ifdef LIB1504
129  /* undocumented cleanup sequence - type UB */
130  curl_easy_cleanup(easy);
131  curl_multi_cleanup(multi);
133 #endif
134 
135 #ifdef LIB1505
136  /* proper cleanup sequence - type PB */
137  curl_multi_remove_handle(multi, easy);
138  curl_easy_cleanup(easy);
139  curl_multi_cleanup(multi);
141 #endif
142 
143  curl_slist_free_all(dns_cache_list);
144 
145  return res;
146 }
#define select_test(A, B, C, D, E)
Definition: test.h:378
#define res_global_init(A)
Definition: test.h:419
int test(char *URL)
Definition: lib1502.c:42
#define easy_setopt(A, B, C)
Definition: test.h:190
#define multi_add_handle(A, B)
Definition: test.h:238
static int res
#define abort_on_test_timeout()
Definition: test.h:404
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: slist.c:89
#define easy_init(A)
Definition: test.h:145
#define multi_fdset(A, B, C, D, E)
Definition: test.h:323
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
#define multi_perform(A, B)
Definition: test.h:293
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle)
#define multi_init(A)
Definition: test.h:166
char * libtest_arg3
Definition: first.c:76
void CURLM
Definition: multi.h:58
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
#define snprintf
Definition: curl_printf.h:42
static CURL * easy[MAX_EASY_HANDLES]
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
#define start_test_timing()
Definition: test.h:383
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15