1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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 ***************************************************************************/
25 * This test uses these funny custom memory callbacks for the only purpose
26 * of verifying that curl_global_init_mem() functionallity is present in
27 * libcurl and that it works unconditionally no matter how libcurl is built,
30 * Do not include memdebug.h in this source file, and do not use directly
31 * memory related functions in this file except those used inside custom
32 * memory callbacks which should be calling 'the real thing'.
45 void *custom_malloc(size_t size);
46 void custom_free(void *ptr);
47 void *custom_realloc(void *ptr, size_t size);
48 char *custom_strdup(const char *ptr);
49 void *custom_calloc(size_t nmemb, size_t size);
52 void *custom_calloc(size_t nmemb, size_t size)
55 printf("seen custom_calloc()\n");
58 return (calloc)(nmemb, size);
61 void *custom_malloc(size_t size)
63 if(!seen_malloc && seen_calloc) {
64 printf("seen custom_malloc()\n");
67 return (malloc)(size);
70 char *custom_strdup(const char *ptr)
72 if(!seen_strdup && seen_malloc) {
73 /* currently (2013.03.13), memory tracking enabled builds do not call
74 the strdup callback, in this case malloc callback and memcpy are used
75 instead. If some day this is changed the following printf() should be
76 uncommented, and a line added to test definition.
77 printf("seen custom_strdup()\n");
84 void *custom_realloc(void *ptr, size_t size)
86 if(!seen_realloc && seen_malloc) {
87 printf("seen custom_realloc()\n");
90 return (realloc)(ptr, size);
93 void custom_free(void *ptr)
95 if(!seen_free && seen_realloc) {
96 printf("seen custom_free()\n");
105 unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
106 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
114 res = curl_global_init_mem(CURL_GLOBAL_ALL,
120 if(res != CURLE_OK) {
121 fprintf(stderr, "curl_global_init_mem() failed\n");
122 return TEST_ERR_MAJOR_BAD;
125 curl = curl_easy_init();
127 fprintf(stderr, "curl_easy_init() failed\n");
128 curl_global_cleanup();
129 return TEST_ERR_MAJOR_BAD;
132 test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */
134 asize = (int)sizeof(a);
135 str = curl_easy_escape(curl, (char *)a, asize); /* uses realloc() */
142 curl_easy_cleanup(curl);
143 curl_global_cleanup();