lib1502.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 /*
00023  * This source code is used for lib1502, lib1503, lib1504 and lib1505 with
00024  * only #ifdefs controlling the cleanup sequence.
00025  *
00026  * Test case 1502 converted from bug report #3575448, identifying a memory
00027  * leak in the CURLOPT_RESOLVE handling with the multi interface.
00028  */
00029 
00030 #include "test.h"
00031 
00032 #ifdef HAVE_LIMITS_H
00033 #include <limits.h>
00034 #endif
00035 
00036 #include "testutil.h"
00037 #include "warnless.h"
00038 #include "memdebug.h"
00039 
00040 #define TEST_HANG_TIMEOUT 60 * 1000
00041 
00042 int test(char *URL)
00043 {
00044   CURL *easy = NULL;
00045   CURLM *multi = NULL;
00046   int still_running;
00047   int res = 0;
00048 
00049   char redirect[160];
00050 
00051   /* DNS cache injection */
00052   struct curl_slist *dns_cache_list;
00053 
00054   snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
00055            libtest_arg3);
00056 
00057   start_test_timing();
00058 
00059   dns_cache_list = curl_slist_append(NULL, redirect);
00060   if(!dns_cache_list) {
00061     fprintf(stderr, "curl_slist_append() failed\n");
00062     return TEST_ERR_MAJOR_BAD;
00063   }
00064 
00065   res_global_init(CURL_GLOBAL_ALL);
00066   if(res) {
00067     curl_slist_free_all(dns_cache_list);
00068     return res;
00069   }
00070 
00071   easy_init(easy);
00072 
00073   easy_setopt(easy, CURLOPT_URL, URL);
00074   easy_setopt(easy, CURLOPT_HEADER, 1L);
00075   easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list);
00076 
00077   multi_init(multi);
00078 
00079   multi_add_handle(multi, easy);
00080 
00081   multi_perform(multi, &still_running);
00082 
00083   abort_on_test_timeout();
00084 
00085   while(still_running) {
00086     struct timeval timeout;
00087     fd_set fdread;
00088     fd_set fdwrite;
00089     fd_set fdexcep;
00090     int maxfd = -99;
00091 
00092     FD_ZERO(&fdread);
00093     FD_ZERO(&fdwrite);
00094     FD_ZERO(&fdexcep);
00095     timeout.tv_sec = 1;
00096     timeout.tv_usec = 0;
00097 
00098     multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
00099 
00100     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00101 
00102     select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00103 
00104     abort_on_test_timeout();
00105 
00106     multi_perform(multi, &still_running);
00107 
00108     abort_on_test_timeout();
00109   }
00110 
00111 test_cleanup:
00112 
00113 #ifdef LIB1502
00114   /* undocumented cleanup sequence - type UA */
00115   curl_multi_cleanup(multi);
00116   curl_easy_cleanup(easy);
00117   curl_global_cleanup();
00118 #endif
00119 
00120 #ifdef LIB1503
00121   /* proper cleanup sequence - type PA */
00122   curl_multi_remove_handle(multi, easy);
00123   curl_multi_cleanup(multi);
00124   curl_easy_cleanup(easy);
00125   curl_global_cleanup();
00126 #endif
00127 
00128 #ifdef LIB1504
00129   /* undocumented cleanup sequence - type UB */
00130   curl_easy_cleanup(easy);
00131   curl_multi_cleanup(multi);
00132   curl_global_cleanup();
00133 #endif
00134 
00135 #ifdef LIB1505
00136   /* proper cleanup sequence - type PB */
00137   curl_multi_remove_handle(multi, easy);
00138   curl_easy_cleanup(easy);
00139   curl_multi_cleanup(multi);
00140   curl_global_cleanup();
00141 #endif
00142 
00143   curl_slist_free_all(dns_cache_list);
00144 
00145   return res;
00146 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05