xref: /curl/tests/libtest/lib1939.c (revision 25cbc2f7)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 
25 #include "test.h"
26 
27 #include "memdebug.h"
28 
test(char * URL)29 CURLcode test(char *URL)
30 {
31   CURLM *multi;
32   CURL *easy;
33   int running_handles;
34 
35   curl_global_init(CURL_GLOBAL_DEFAULT);
36 
37   multi = curl_multi_init();
38   if(multi) {
39     easy = curl_easy_init();
40     if(easy) {
41       CURLcode c;
42       CURLMcode m;
43 
44       /* Crash only happens when using HTTPS */
45       c = curl_easy_setopt(easy, CURLOPT_URL, URL);
46       if(!c)
47         /* Any old HTTP tunneling proxy will do here */
48         c = curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
49 
50       if(!c) {
51 
52         /* We're going to drive the transfer using multi interface here,
53            because we want to stop during the middle. */
54         m = curl_multi_add_handle(multi, easy);
55 
56         if(!m)
57           /* Run the multi handle once, just enough to start establishing an
58              HTTPS connection. */
59           m = curl_multi_perform(multi, &running_handles);
60 
61         if(m)
62           fprintf(stderr, "curl_multi_perform failed\n");
63       }
64       /* Close the easy handle *before* the multi handle. Doing it the other
65          way around avoids the issue. */
66       curl_easy_cleanup(easy);
67     }
68     curl_multi_cleanup(multi); /* double-free happens here */
69   }
70   curl_global_cleanup();
71   return CURLE_OK;
72 }
73