diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2020-06-06 23:10:18 +0200 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2020-06-08 16:10:53 +0200 | 
| commit | 54d3769761e5a842aefa9462cd0eaed00da400d0 (patch) | |
| tree | 61fea40c7b150c3ac832a441c8b251183f678b78 /tests | |
| parent | 52777754623628f91ee2316acee52e68831f3e02 (diff) | |
Curl_addrinfo: use one malloc instead of three
To reduce the amount of allocations needed for creating a Curl_addrinfo
struct, make a single larger malloc instead of three separate smaller
ones.
Closes #5533
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/unit1305.c | 21 | 
1 files changed, 8 insertions, 13 deletions
diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c index f3cd9d8f0..50f6da8bb 100644 --- a/tests/unit/unit1305.c +++ b/tests/unit/unit1305.c @@ -76,23 +76,18 @@ static void unit_stop(void)  static struct Curl_addrinfo *fake_ai(void)  {    static struct Curl_addrinfo *ai; +  static const char dummy[]="dummy"; +  size_t namelen = sizeof(dummy); /* including the zero terminator */ -  ai = calloc(1, sizeof(struct Curl_addrinfo)); +  ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + +              namelen);    if(!ai)      return NULL; -  ai->ai_canonname = strdup("dummy"); -  if(!ai->ai_canonname) { -    free(ai); -    return NULL; -  } - -  ai->ai_addr = calloc(1, sizeof(struct sockaddr_in)); -  if(!ai->ai_addr) { -    free(ai->ai_canonname); -    free(ai); -    return NULL; -  } +  ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); +  ai->ai_canonname = (void *)((char *)ai->ai_addr + +                              sizeof(struct sockaddr_in)); +  memcpy(ai->ai_canonname, dummy, namelen);    ai->ai_family = AF_INET;    ai->ai_addrlen = sizeof(struct sockaddr_in);  | 
