diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2020-05-28 18:30:47 +0200 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2020-05-30 23:14:33 +0200 | 
| commit | c4e6968127e876b01e5e0b4b7cdbc49d5267530c (patch) | |
| tree | 7d74ba1d30f99ac91b050fbb6c5b44338c56e88f /tests | |
| parent | 842f73de58f38bd6e285e08bbd1adb6c17cb62cd (diff) | |
url: alloc the download buffer at transfer start
... and free it as soon as the transfer is done. It removes the extra
alloc when a new size is set with setopt() and reduces memory for unused
easy handles.
In addition: the closure_handle now doesn't use an allocated buffer at
all but the smallest supported size as a stack based one.
Closes #5472
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/data/test509 | 5 | ||||
| -rw-r--r-- | tests/libtest/lib509.c | 63 | 
2 files changed, 16 insertions, 52 deletions
diff --git a/tests/data/test509 b/tests/data/test509 index 5de1599e1..0e0dd212b 100644 --- a/tests/data/test509 +++ b/tests/data/test509 @@ -34,10 +34,7 @@ nothing  # Verify data after the test has been "shot"  <verify>  <stdout> -seen custom_calloc() -seen custom_malloc() -seen custom_realloc() -seen custom_free() +Callbacks were invoked!  </stdout>  </verify> diff --git a/tests/libtest/lib509.c b/tests/libtest/lib509.c index e8e803ffc..1fb2d3445 100644 --- a/tests/libtest/lib509.c +++ b/tests/libtest/lib509.c @@ -5,7 +5,7 @@   *                            | (__| |_| |  _ <| |___   *                             \___|\___/|_| \_\_____|   * - * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.   *   * This software is licensed as described in the file COPYING, which   * you should have received as part of this distribution. The terms @@ -34,70 +34,35 @@   * memory callbacks which should be calling 'the real thing'.   */ -/* -#include "memdebug.h" -*/ - -static int seen_malloc = 0; -static int seen_free = 0; -static int seen_realloc = 0; -static int seen_strdup = 0; -static int seen_calloc = 0; - -void *custom_malloc(size_t size); -void custom_free(void *ptr); -void *custom_realloc(void *ptr, size_t size); -char *custom_strdup(const char *ptr); -void *custom_calloc(size_t nmemb, size_t size); +static int seen; - -void *custom_calloc(size_t nmemb, size_t size) +static void *custom_calloc(size_t nmemb, size_t size)  { -  if(!seen_calloc) { -    printf("seen custom_calloc()\n"); -    seen_calloc = 1; -  } +  seen++;    return (calloc)(nmemb, size);  } -void *custom_malloc(size_t size) +static void *custom_malloc(size_t size)  { -  if(!seen_malloc && seen_calloc) { -    printf("seen custom_malloc()\n"); -    seen_malloc = 1; -  } +  seen++;    return (malloc)(size);  } -char *custom_strdup(const char *ptr) +static char *custom_strdup(const char *ptr)  { -  if(!seen_strdup && seen_malloc) { -    /* currently (2013.03.13), memory tracking enabled builds do not call -       the strdup callback, in this case malloc callback and memcpy are used -       instead. If some day this is changed the following printf() should be -       uncommented, and a line added to test definition. -    printf("seen custom_strdup()\n"); -    */ -    seen_strdup = 1; -  } +  seen++;    return (strdup)(ptr);  } -void *custom_realloc(void *ptr, size_t size) +static void *custom_realloc(void *ptr, size_t size)  { -  if(!seen_realloc && seen_malloc) { -    printf("seen custom_realloc()\n"); -    seen_realloc = 1; -  } +  seen++;    return (realloc)(ptr, size);  } -void custom_free(void *ptr) +static void custom_free(void *ptr)  { -  if(!seen_free && seen_realloc) { -    printf("seen custom_free()\n"); -    seen_free = 1; -  } +  seen++;    (free)(ptr);  } @@ -110,7 +75,6 @@ int test(char *URL)    CURL *curl;    int asize;    char *str = NULL; -    (void)URL;    res = curl_global_init_mem(CURL_GLOBAL_ALL, @@ -136,6 +100,9 @@ int test(char *URL)    asize = (int)sizeof(a);    str = curl_easy_escape(curl, (char *)a, asize); /* uses realloc() */ +  if(seen) +    printf("Callbacks were invoked!\n"); +  test_cleanup:    if(str)  | 
