mirror of
https://github.com/curl/curl.git
synced 2026-08-25 02:33:31 +03:00
tool: replace three malloc + copy with memdup0
The function already existed for private use in var.c Closes #18185
This commit is contained in:
parent
a7bacfe6e0
commit
b3b7d65239
5 changed files with 21 additions and 24 deletions
16
src/var.c
16
src/var.c
|
|
@ -31,23 +31,13 @@
|
|||
#include "tool_parsecfg.h"
|
||||
#include "tool_paramhlp.h"
|
||||
#include "tool_writeout_json.h"
|
||||
#include "tool_strdup.h"
|
||||
#include "var.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define MAX_EXPAND_CONTENT 10000000
|
||||
#define MAX_VAR_LEN 128 /* max length of a name */
|
||||
|
||||
static char *Memdup(const char *data, size_t len)
|
||||
{
|
||||
char *p = malloc(len + 1);
|
||||
if(!p)
|
||||
return NULL;
|
||||
if(len)
|
||||
memcpy(p, data, len);
|
||||
p[len] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* free everything */
|
||||
void varcleanup(struct GlobalConfig *global)
|
||||
{
|
||||
|
|
@ -208,7 +198,7 @@ static ParameterError varfunc(struct GlobalConfig *global,
|
|||
free(c);
|
||||
|
||||
clen = curlx_dyn_len(out);
|
||||
c = Memdup(curlx_dyn_ptr(out), clen);
|
||||
c = memdup0(curlx_dyn_ptr(out), clen);
|
||||
if(!c) {
|
||||
err = PARAM_NO_MEM;
|
||||
break;
|
||||
|
|
@ -379,7 +369,7 @@ static ParameterError addvariable(struct GlobalConfig *global,
|
|||
if(p) {
|
||||
memcpy(p->name, name, nlen);
|
||||
|
||||
p->content = contalloc ? content : Memdup(content, clen);
|
||||
p->content = contalloc ? content : memdup0(content, clen);
|
||||
if(p->content) {
|
||||
p->clen = clen;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue