tool: replace three malloc + copy with memdup0

The function already existed for private use in var.c

Closes #18185
This commit is contained in:
Daniel Stenberg 2025-08-05 14:24:15 +02:00
parent a7bacfe6e0
commit b3b7d65239
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 21 additions and 24 deletions

View file

@ -27,6 +27,7 @@
#include "tool_doswin.h"
#include "tool_urlglob.h"
#include "tool_vms.h"
#include "tool_strdup.h"
#include "memdebug.h" /* keep this as LAST include */
#define GLOBERROR(string, column, code) \
@ -45,13 +46,10 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
if(!pat->content.Set.elements)
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
pat->content.Set.elements[0] = malloc(len + 1);
pat->content.Set.elements[0] = memdup0(fixed, len);
if(!pat->content.Set.elements[0])
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
memcpy(pat->content.Set.elements[0], fixed, len);
pat->content.Set.elements[0][len] = 0;
return CURLE_OK;
}