mirror of
https://github.com/curl/curl.git
synced 2026-07-27 15:28:54 +03:00
build: stop overriding standard memory allocation functions
Before this patch curl used the C preprocessor to override standard memory allocation symbols: malloc, calloc, strdup, realloc, free. The goal of these is to replace them with curl's debug wrappers in `CURLDEBUG` builds, another was to replace them with the wrappers calling user-defined allocators in libcurl. This solution needed a bunch of workarounds to avoid breaking external headers: it relied on include order to do the overriding last. For "unity" builds it needed to reset overrides before external includes. Also in test apps, which are always built as single source files. It also needed the `(symbol)` trick to avoid overrides in some places. This would still not fix cases where the standard symbols were macros. It was also fragile and difficult to figure out which was the actual function behind an alloc or free call in a specific piece of code. This in turn caused bugs where the wrong allocator was accidentally called. To avoid these problems, this patch replaces this solution with `curlx_`-prefixed allocator macros, and mapping them _once_ to either the libcurl wrappers, the debug wrappers or the standard ones, matching the rest of the code in libtests. This concludes the long journey to avoid redefining standard functions in the curl codebase. Note: I did not update `packages/OS400/*.c` sources. They did not `#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning the overrides were never applied to them. This may or may not have been correct. For now I suppressed the direct use of standard allocators via a local `.checksrc`. Probably they (except for `curlcl.c`) should be updated to include `curl_setup.h` and use the `curlx_` macros. This patch changes mappings in two places: - `lib/curl_threads.c` in libtests: Before this patch it mapped to libcurl allocators. After, it maps to standard allocators, like the rest of libtests code. - `units`: before this patch it mapped to standard allocators. After, it maps to libcurl allocators. Also: - drop all position-dependent `curl_memory.h` and `memdebug.h` includes, and delete the now unnecessary headers. - rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other allocators. - map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`). To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`. - multibyte: map `curlx_convert_*()` to `_strdup()` on Windows (was: `strdup()`). - src: do not reuse the `strdup` name for the local replacement. - lib509: call `_strdup()` on Windows (was: `strdup()`). - test1132: delete test obsoleted by this patch. - CHECKSRC.md: update text for `SNPRINTF`. - checksrc: ban standard allocator symbols. Follow-up tob12da22db1#18866 Follow-up todb98daab05#18844 Follow-up to4deea9396b#18814 Follow-up to9678ff5b1b#18776 Follow-up to10bac43b87#18774 Follow-up to20142f5d06#18634 Follow-up tobf7375ecc5#18503 Follow-up to9863599d69#18502 Follow-up to3bb5e58c10#17827 Closes #19626
This commit is contained in:
parent
bfc3d131b6
commit
193cb00ce9
471 changed files with 1456 additions and 2785 deletions
|
|
@ -78,7 +78,6 @@ if($c)
|
|||
|
||||
print <<HEAD
|
||||
#include <zlib.h>
|
||||
#include <memdebug.h> /* keep this as LAST include */
|
||||
static const unsigned char hugehelpgz[] = {
|
||||
/* This mumbo-jumbo is the huge help text compressed with gzip.
|
||||
Thanks to this operation, the size of this data shrank from $gzip
|
||||
|
|
@ -105,13 +104,13 @@ HEAD
|
|||
static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size)
|
||||
{
|
||||
(void)opaque;
|
||||
/* not a typo, keep it calloc() */
|
||||
return (voidpf) calloc(items, size);
|
||||
/* not a typo, keep it curlx_calloc() */
|
||||
return (voidpf)curlx_calloc(items, size);
|
||||
}
|
||||
static void zfree_func(voidpf opaque, voidpf ptr)
|
||||
{
|
||||
(void)opaque;
|
||||
free(ptr);
|
||||
curlx_free(ptr);
|
||||
}
|
||||
|
||||
#define HEADERLEN 10
|
||||
|
|
@ -136,7 +135,7 @@ void hugehelp(void)
|
|||
if(inflateInit2(&z, -MAX_WBITS) != Z_OK)
|
||||
return;
|
||||
|
||||
buf = malloc(BUF_SIZE);
|
||||
buf = curlx_malloc(BUF_SIZE);
|
||||
if(buf) {
|
||||
while(1) {
|
||||
z.avail_out = BUF_SIZE;
|
||||
|
|
@ -150,7 +149,7 @@ void hugehelp(void)
|
|||
else
|
||||
break; /* error */
|
||||
}
|
||||
free(buf);
|
||||
curlx_free(buf);
|
||||
}
|
||||
inflateEnd(&z);
|
||||
}
|
||||
|
|
@ -176,7 +175,7 @@ void showhelp(const char *trigger, const char *arg, const char *endarg)
|
|||
if(inflateInit2(&z, -MAX_WBITS) != Z_OK)
|
||||
return;
|
||||
|
||||
buf = malloc(BUF_SIZE);
|
||||
buf = curlx_malloc(BUF_SIZE);
|
||||
if(buf) {
|
||||
while(1) {
|
||||
z.avail_out = BUF_SIZE;
|
||||
|
|
@ -192,7 +191,7 @@ void showhelp(const char *trigger, const char *arg, const char *endarg)
|
|||
else
|
||||
break; /* error */
|
||||
}
|
||||
free(buf);
|
||||
curlx_free(buf);
|
||||
}
|
||||
inflateEnd(&z);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@
|
|||
|
||||
#include "slist_wc.h"
|
||||
|
||||
/* The last #include files should be: */
|
||||
#include "memdebug.h"
|
||||
|
||||
/*
|
||||
* slist_wc_append() appends a string to the linked list. This function can be
|
||||
* used as an initialization function as well as an append function.
|
||||
|
|
@ -44,7 +41,7 @@ struct slist_wc *slist_wc_append(struct slist_wc *list,
|
|||
return NULL;
|
||||
|
||||
if(!list) {
|
||||
list = malloc(sizeof(struct slist_wc));
|
||||
list = curlx_malloc(sizeof(struct slist_wc));
|
||||
|
||||
if(!list) {
|
||||
curl_slist_free_all(new_item);
|
||||
|
|
@ -68,7 +65,7 @@ void slist_wc_free_all(struct slist_wc *list)
|
|||
return;
|
||||
|
||||
curl_slist_free_all(list->first);
|
||||
free(list);
|
||||
curlx_free(list);
|
||||
}
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#endif
|
||||
|
||||
#include "terminal.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
#include "tool_bname.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifndef HAVE_BASENAME
|
||||
|
||||
char *tool_basename(char *path)
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
#include "tool_cb_dbg.h"
|
||||
#include "tool_util.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static void dump(const char *timebuf, const char *idsbuf, const char *text,
|
||||
FILE *stream, const unsigned char *ptr, size_t size,
|
||||
trace tracetype, curl_infotype infotype);
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@
|
|||
#include "tool_libinfo.h"
|
||||
#include "tool_strdup.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static char *parse_filename(const char *ptr, size_t len);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
@ -212,14 +210,14 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|||
if(filename) {
|
||||
if(outs->stream) {
|
||||
/* indication of problem, get out! */
|
||||
free(filename);
|
||||
curlx_free(filename);
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
|
||||
if(per->config->output_dir) {
|
||||
outs->filename = curl_maprintf("%s/%s", per->config->output_dir,
|
||||
filename);
|
||||
free(filename);
|
||||
curlx_free(filename);
|
||||
if(!outs->filename)
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
|
|
@ -252,7 +250,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|||
if(clone) {
|
||||
struct curl_slist *old = hdrcbdata->headlist;
|
||||
hdrcbdata->headlist = curl_slist_append(old, clone);
|
||||
free(clone);
|
||||
curlx_free(clone);
|
||||
if(!hdrcbdata->headlist) {
|
||||
curl_slist_free_all(old);
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
|
|
@ -479,7 +477,7 @@ locdone:
|
|||
curl_free(finalurl);
|
||||
curl_free(scheme);
|
||||
curl_url_cleanup(u);
|
||||
free(copyloc);
|
||||
curlx_free(copyloc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@
|
|||
#include "tool_operate.h"
|
||||
#include "terminal.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define MAX_BARLENGTH 400
|
||||
#define MIN_BARLENGTH 20
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@
|
|||
#include "tool_util.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifndef _WIN32
|
||||
/* Wait up to a number of milliseconds for socket activity. This function
|
||||
waits on read activity on a file descriptor that is not a socket which
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@
|
|||
#include "tool_operate.h"
|
||||
#include "tool_cb_see.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_SEEKFUNCTION
|
||||
**
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
#include "tool_cb_wrt.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define OPENMODE S_IREAD | S_IWRITE
|
||||
#else
|
||||
|
|
@ -211,8 +209,8 @@ static size_t win_console(intptr_t fhnd, struct OutStruct *outs,
|
|||
|
||||
/* grow the buffer if needed */
|
||||
if(len > global->term.len) {
|
||||
wchar_t *buf = (wchar_t *) realloc(global->term.buf,
|
||||
len * sizeof(wchar_t));
|
||||
wchar_t *buf = (wchar_t *)curlx_realloc(global->term.buf,
|
||||
len * sizeof(wchar_t));
|
||||
if(!buf)
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
global->term.len = len;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "tool_paramhlp.h"
|
||||
#include "tool_main.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static struct GlobalConfig globalconf;
|
||||
struct GlobalConfig *global;
|
||||
|
|
@ -36,7 +35,7 @@ struct GlobalConfig *global;
|
|||
struct OperationConfig *config_alloc(void)
|
||||
{
|
||||
struct OperationConfig *config =
|
||||
calloc(1, sizeof(struct OperationConfig));
|
||||
curlx_calloc(1, sizeof(struct OperationConfig));
|
||||
if(!config)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -199,7 +198,7 @@ void config_free(struct OperationConfig *config)
|
|||
struct OperationConfig *prev = last->prev;
|
||||
|
||||
free_config_fields(last);
|
||||
free(last);
|
||||
curlx_free(last);
|
||||
|
||||
last = prev;
|
||||
}
|
||||
|
|
@ -236,12 +235,12 @@ CURLcode globalconf_init(void)
|
|||
|
||||
if(result) {
|
||||
errorf("error retrieving curl library information");
|
||||
free(global->first);
|
||||
curlx_free(global->first);
|
||||
}
|
||||
}
|
||||
else {
|
||||
errorf("error initializing curl library");
|
||||
free(global->first);
|
||||
curlx_free(global->first);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -263,7 +262,7 @@ static void free_globalconfig(void)
|
|||
tool_safefree(global->ssl_sessions);
|
||||
tool_safefree(global->libcurl);
|
||||
#ifdef _WIN32
|
||||
free(global->term.buf);
|
||||
curlx_free(global->term.buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
#define checkprefix(a,b) curl_strnequal(b, STRCONST(a))
|
||||
|
||||
#define tool_safefree(ptr) \
|
||||
do { free((ptr)); (ptr) = NULL;} while(0)
|
||||
do { curlx_free((ptr)); (ptr) = NULL;} while(0)
|
||||
|
||||
extern struct GlobalConfig *global;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@
|
|||
#include "tool_dirhie.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__))
|
||||
# define mkdir(x,y) (mkdir)((x))
|
||||
# ifndef F_OK
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@
|
|||
#include "tool_doswin.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef _WIN32
|
||||
# undef PATH_MAX
|
||||
# define PATH_MAX MAX_PATH
|
||||
|
|
@ -133,7 +131,7 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name,
|
|||
if(len > max_sanitized_len)
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
target = strdup(file_name);
|
||||
target = curlx_strdup(file_name);
|
||||
if(!target)
|
||||
return SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
|
||||
|
|
@ -183,28 +181,28 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name,
|
|||
|
||||
#ifdef MSDOS
|
||||
sc = msdosify(&p, target, flags);
|
||||
free(target);
|
||||
curlx_free(target);
|
||||
if(sc)
|
||||
return sc;
|
||||
target = p;
|
||||
len = strlen(target);
|
||||
|
||||
if(len > max_sanitized_len) {
|
||||
free(target);
|
||||
curlx_free(target);
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!(flags & SANITIZE_ALLOW_RESERVED)) {
|
||||
sc = rename_if_reserved_dos(&p, target, flags);
|
||||
free(target);
|
||||
curlx_free(target);
|
||||
if(sc)
|
||||
return sc;
|
||||
target = p;
|
||||
len = strlen(target);
|
||||
|
||||
if(len > max_sanitized_len) {
|
||||
free(target);
|
||||
curlx_free(target);
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
}
|
||||
|
|
@ -415,7 +413,7 @@ static SANITIZEcode msdosify(char **const sanitized, const char *file_name,
|
|||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
|
||||
*sanitized = strdup(dos_name);
|
||||
*sanitized = curlx_strdup(dos_name);
|
||||
return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
#endif /* MSDOS */
|
||||
|
|
@ -457,7 +455,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized,
|
|||
#ifndef MSDOS
|
||||
if((flags & SANITIZE_ALLOW_PATH) &&
|
||||
file_name[0] == '\\' && file_name[1] == '\\') {
|
||||
*sanitized = strdup(file_name);
|
||||
*sanitized = curlx_strdup(file_name);
|
||||
if(!*sanitized)
|
||||
return SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
return SANITIZE_ERR_OK;
|
||||
|
|
@ -544,7 +542,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized,
|
|||
}
|
||||
#endif
|
||||
|
||||
*sanitized = strdup(fname);
|
||||
*sanitized = curlx_strdup(fname);
|
||||
return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
|
@ -597,7 +595,7 @@ CURLcode FindWin32CACert(struct OperationConfig *config,
|
|||
char *mstr = curlx_convert_tchar_to_UTF8(buf);
|
||||
tool_safefree(config->cacert);
|
||||
if(mstr)
|
||||
config->cacert = strdup(mstr);
|
||||
config->cacert = curlx_strdup(mstr);
|
||||
curlx_unicodefree(mstr);
|
||||
if(!config->cacert)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -801,7 +799,7 @@ ThreadCleanup:
|
|||
if(socket_w != CURL_SOCKET_BAD)
|
||||
sclose(socket_w);
|
||||
|
||||
free(tdata);
|
||||
curlx_free(tdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -824,9 +822,10 @@ curl_socket_t win32_stdin_read_thread(void)
|
|||
|
||||
do {
|
||||
/* Prepare handles for thread */
|
||||
tdata = (struct win_thread_data*)calloc(1, sizeof(struct win_thread_data));
|
||||
tdata = (struct win_thread_data*)
|
||||
curlx_calloc(1, sizeof(struct win_thread_data));
|
||||
if(!tdata) {
|
||||
errorf("calloc() error");
|
||||
errorf("curlx_calloc() error");
|
||||
break;
|
||||
}
|
||||
/* Create the listening socket for the thread. When it starts, it will
|
||||
|
|
@ -937,7 +936,7 @@ curl_socket_t win32_stdin_read_thread(void)
|
|||
if(tdata->socket_l != CURL_SOCKET_BAD)
|
||||
sclose(tdata->socket_l);
|
||||
|
||||
free(tdata);
|
||||
curlx_free(tdata);
|
||||
}
|
||||
|
||||
return CURL_SOCKET_BAD;
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
#include "tool_easysrc.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* global variable definitions, for easy-interface source code generation */
|
||||
|
||||
struct slist_wc *easysrc_decl; /* Variable declarations */
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@
|
|||
#include "tool_findfile.h"
|
||||
#include "tool_cfgable.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
struct finder {
|
||||
const char *env;
|
||||
const char *append;
|
||||
|
|
@ -75,7 +73,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore)
|
|||
if(c) {
|
||||
int fd = curlx_open(c, O_RDONLY);
|
||||
if(fd >= 0) {
|
||||
char *path = strdup(c);
|
||||
char *path = curlx_strdup(c);
|
||||
close(fd);
|
||||
curl_free(c);
|
||||
return path;
|
||||
|
|
|
|||
|
|
@ -30,13 +30,11 @@
|
|||
#include "tool_formparse.h"
|
||||
#include "tool_parsecfg.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* tool_mime functions. */
|
||||
static struct tool_mime *tool_mime_new(struct tool_mime *parent,
|
||||
toolmimekind kind)
|
||||
{
|
||||
struct tool_mime *m = (struct tool_mime *) calloc(1, sizeof(*m));
|
||||
struct tool_mime *m = (struct tool_mime *)curlx_calloc(1, sizeof(*m));
|
||||
|
||||
if(m) {
|
||||
m->kind = kind;
|
||||
|
|
@ -60,11 +58,11 @@ static struct tool_mime *tool_mime_new_data(struct tool_mime *parent,
|
|||
char *mime_data_copy;
|
||||
struct tool_mime *m = NULL;
|
||||
|
||||
mime_data_copy = strdup(mime_data);
|
||||
mime_data_copy = curlx_strdup(mime_data);
|
||||
if(mime_data_copy) {
|
||||
m = tool_mime_new(parent, TOOLMIME_DATA);
|
||||
if(!m)
|
||||
free(mime_data_copy);
|
||||
curlx_free(mime_data_copy);
|
||||
else
|
||||
m->data = mime_data_copy;
|
||||
}
|
||||
|
|
@ -107,11 +105,11 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
|
|||
*errcode = CURLE_OUT_OF_MEMORY;
|
||||
if(strcmp(filename, "-")) {
|
||||
/* This is a normal file. */
|
||||
char *filedup = strdup(filename);
|
||||
char *filedup = curlx_strdup(filename);
|
||||
if(filedup) {
|
||||
m = tool_mime_new(parent, TOOLMIME_FILE);
|
||||
if(!m)
|
||||
free(filedup);
|
||||
curlx_free(filedup);
|
||||
else {
|
||||
m->data = filedup;
|
||||
if(!isremotefile)
|
||||
|
|
@ -152,7 +150,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
|
|||
default:
|
||||
if(!stdinsize) {
|
||||
/* Zero-length data has been freed. Re-create it. */
|
||||
data = strdup("");
|
||||
data = curlx_strdup("");
|
||||
if(!data)
|
||||
return m;
|
||||
}
|
||||
|
|
@ -190,7 +188,7 @@ void tool_mime_free(struct tool_mime *mime)
|
|||
tool_safefree(mime->encoder);
|
||||
tool_safefree(mime->data);
|
||||
curl_slist_free_all(mime->headers);
|
||||
free(mime);
|
||||
curlx_free(mime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -711,7 +709,7 @@ static int get_param_part(char endchar,
|
|||
#define SET_TOOL_MIME_PTR(m, field) \
|
||||
do { \
|
||||
if(field) { \
|
||||
(m)->field = strdup(field); \
|
||||
(m)->field = curlx_strdup(field); \
|
||||
if(!(m)->field) \
|
||||
goto fail; \
|
||||
} \
|
||||
|
|
@ -745,7 +743,7 @@ int formparse(const char *input,
|
|||
}
|
||||
|
||||
/* Make a copy we can overwrite. */
|
||||
contents = strdup(input);
|
||||
contents = curlx_strdup(input);
|
||||
if(!contents)
|
||||
goto fail;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,22 +38,20 @@
|
|||
#include "tool_help.h"
|
||||
#include "var.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define ALLOW_BLANK TRUE
|
||||
#define DENY_BLANK FALSE
|
||||
|
||||
static ParameterError getstr(char **str, const char *val, bool allowblank)
|
||||
{
|
||||
if(*str) {
|
||||
free(*str);
|
||||
curlx_free(*str);
|
||||
*str = NULL;
|
||||
}
|
||||
DEBUGASSERT(val);
|
||||
if(!allowblank && !val[0])
|
||||
return PARAM_BLANK_STRING;
|
||||
|
||||
*str = strdup(val);
|
||||
*str = curlx_strdup(val);
|
||||
if(!*str)
|
||||
return PARAM_NO_MEM;
|
||||
|
||||
|
|
@ -64,14 +62,14 @@ static ParameterError getstrn(char **str, const char *val,
|
|||
size_t len, bool allowblank)
|
||||
{
|
||||
if(*str) {
|
||||
free(*str);
|
||||
curlx_free(*str);
|
||||
*str = NULL;
|
||||
}
|
||||
DEBUGASSERT(val);
|
||||
if(!allowblank && !val[0])
|
||||
return PARAM_BLANK_STRING;
|
||||
|
||||
*str = malloc(len + 1);
|
||||
*str = curlx_malloc(len + 1);
|
||||
if(!*str)
|
||||
return PARAM_NO_MEM;
|
||||
|
||||
|
|
@ -407,13 +405,13 @@ ParameterError parse_cert_parameter(const char *cert_parameter,
|
|||
* means no passphrase was given and no characters escaped */
|
||||
if(curl_strnequal(cert_parameter, "pkcs11:", 7) ||
|
||||
!strpbrk(cert_parameter, ":\\")) {
|
||||
*certname = strdup(cert_parameter);
|
||||
*certname = curlx_strdup(cert_parameter);
|
||||
if(!*certname)
|
||||
return PARAM_NO_MEM;
|
||||
return PARAM_OK;
|
||||
}
|
||||
/* deal with escaped chars; find unescaped colon if it exists */
|
||||
certname_place = malloc(param_length + 1);
|
||||
certname_place = curlx_malloc(param_length + 1);
|
||||
if(!certname_place) {
|
||||
err = PARAM_NO_MEM;
|
||||
goto done;
|
||||
|
|
@ -475,7 +473,7 @@ ParameterError parse_cert_parameter(const char *cert_parameter,
|
|||
* above; if we are still here, this is a separating colon */
|
||||
param_place++;
|
||||
if(*param_place) {
|
||||
*passphrase = strdup(param_place);
|
||||
*passphrase = curlx_strdup(param_place);
|
||||
if(!*passphrase)
|
||||
err = PARAM_NO_MEM;
|
||||
}
|
||||
|
|
@ -527,10 +525,10 @@ GetFileAndPassword(const char *nextarg, char **file, char **password)
|
|||
/* nextarg is never NULL here */
|
||||
err = parse_cert_parameter(nextarg, &certname, &passphrase);
|
||||
if(!err) {
|
||||
free(*file);
|
||||
curlx_free(*file);
|
||||
*file = certname;
|
||||
if(passphrase) {
|
||||
free(*password);
|
||||
curlx_free(*password);
|
||||
*password = passphrase;
|
||||
}
|
||||
}
|
||||
|
|
@ -668,7 +666,7 @@ static ParameterError data_urlencode(const char *nextarg,
|
|||
if(!postdata) {
|
||||
/* no data from the file, point to a zero byte string to make this
|
||||
get sent as a POST anyway */
|
||||
postdata = strdup("");
|
||||
postdata = curlx_strdup("");
|
||||
if(!postdata)
|
||||
return PARAM_NO_MEM;
|
||||
size = 0;
|
||||
|
|
@ -870,7 +868,7 @@ static ParameterError url_query(const char *nextarg,
|
|||
|
||||
if(*nextarg == '+') {
|
||||
/* use without encoding */
|
||||
query = strdup(&nextarg[1]);
|
||||
query = curlx_strdup(&nextarg[1]);
|
||||
if(!query)
|
||||
err = PARAM_NO_MEM;
|
||||
}
|
||||
|
|
@ -880,11 +878,11 @@ static ParameterError url_query(const char *nextarg,
|
|||
if(!err) {
|
||||
if(config->query) {
|
||||
CURLcode result = curlx_dyn_addf(&dyn, "%s&%s", config->query, query);
|
||||
free(query);
|
||||
curlx_free(query);
|
||||
if(result)
|
||||
err = PARAM_NO_MEM;
|
||||
else {
|
||||
free(config->query);
|
||||
curlx_free(config->query);
|
||||
config->query = curlx_dyn_ptr(&dyn);
|
||||
}
|
||||
}
|
||||
|
|
@ -944,7 +942,7 @@ static ParameterError set_data(cmdline_t cmd,
|
|||
if(!postdata) {
|
||||
/* no data from the file, point to a zero byte string to make this
|
||||
get sent as a POST anyway */
|
||||
postdata = strdup("");
|
||||
postdata = curlx_strdup("");
|
||||
if(!postdata)
|
||||
return PARAM_NO_MEM;
|
||||
}
|
||||
|
|
@ -1240,7 +1238,7 @@ static ParameterError parse_ech(struct OperationConfig *config,
|
|||
if(err)
|
||||
return err;
|
||||
config->ech_config = curl_maprintf("ecl:%s",tmpcfg);
|
||||
free(tmpcfg);
|
||||
curlx_free(tmpcfg);
|
||||
if(!config->ech_config)
|
||||
return PARAM_NO_MEM;
|
||||
} /* file done */
|
||||
|
|
@ -1424,8 +1422,8 @@ static ParameterError parse_range(struct OperationConfig *config,
|
|||
"Appending one for you");
|
||||
curl_msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-",
|
||||
value);
|
||||
free(config->range);
|
||||
config->range = strdup(buffer);
|
||||
curlx_free(config->range);
|
||||
config->range = curlx_strdup(buffer);
|
||||
if(!config->range)
|
||||
err = PARAM_NO_MEM;
|
||||
}
|
||||
|
|
@ -1509,8 +1507,8 @@ static ParameterError parse_verbose(bool toggle)
|
|||
switch(global->verbosity) {
|
||||
case 0:
|
||||
global->verbosity = 1;
|
||||
free(global->trace_dump);
|
||||
global->trace_dump = strdup("%");
|
||||
curlx_free(global->trace_dump);
|
||||
global->trace_dump = curlx_strdup("%");
|
||||
if(!global->trace_dump)
|
||||
err = PARAM_NO_MEM;
|
||||
else {
|
||||
|
|
@ -3021,7 +3019,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
|
|||
|
||||
error:
|
||||
if(nextalloc)
|
||||
free(CURL_UNCONST(nextarg));
|
||||
curlx_free(CURL_UNCONST(nextarg));
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@
|
|||
#endif
|
||||
#include "tool_getpass.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef __VMS
|
||||
/* VMS implementation */
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@
|
|||
#include "tool_cfgable.h"
|
||||
#include "terminal.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
struct category_descriptors {
|
||||
const char *opt;
|
||||
const char *desc;
|
||||
|
|
@ -364,7 +362,7 @@ void tool_version_info(void)
|
|||
#ifdef CURL_CA_EMBED
|
||||
++feat_ext_count;
|
||||
#endif
|
||||
feat_ext = malloc(sizeof(*feature_names) * (feat_ext_count + 1));
|
||||
feat_ext = curlx_malloc(sizeof(*feature_names) * (feat_ext_count + 1));
|
||||
if(feat_ext) {
|
||||
memcpy((void *)feat_ext, feature_names,
|
||||
sizeof(*feature_names) * feature_count);
|
||||
|
|
@ -379,7 +377,7 @@ void tool_version_info(void)
|
|||
for(builtin = feat_ext; *builtin; ++builtin)
|
||||
curl_mprintf(" %s", *builtin);
|
||||
puts(""); /* newline */
|
||||
free((void *)feat_ext);
|
||||
curlx_free((void *)feat_ext);
|
||||
}
|
||||
}
|
||||
if(strcmp(CURL_VERSION, curlinfo->version)) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include "tool_msgs.h"
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_helpers.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/*
|
||||
** Helper functions that are used from more than one source file.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "tool_cfgable.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_ipfs.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* input string ends in slash? */
|
||||
static bool has_trailing_slash(const char *input)
|
||||
|
|
@ -45,7 +44,7 @@ static char *ipfs_gateway(void)
|
|||
char *gateway_env = getenv("IPFS_GATEWAY");
|
||||
|
||||
if(gateway_env)
|
||||
return strdup(gateway_env);
|
||||
return curlx_strdup(gateway_env);
|
||||
|
||||
/* Try to find the gateway in the IPFS data folder. */
|
||||
ipfs_path_c = curl_getenv("IPFS_PATH");
|
||||
|
|
@ -133,7 +132,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
|
|||
if(config->ipfs_gateway) {
|
||||
if(!curl_url_set(gatewayurl, CURLUPART_URL, config->ipfs_gateway,
|
||||
CURLU_GUESS_SCHEME)) {
|
||||
gateway = strdup(config->ipfs_gateway);
|
||||
gateway = curlx_strdup(config->ipfs_gateway);
|
||||
if(!gateway) {
|
||||
result = CURLE_URL_MALFORMAT;
|
||||
goto clean;
|
||||
|
|
@ -200,8 +199,8 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
|
|||
if(curl_url_get(uh, CURLUPART_URL, &cloneurl, CURLU_URLENCODE)) {
|
||||
goto clean;
|
||||
}
|
||||
/* we need to strdup the URL so that we can call free() on it later */
|
||||
*url = strdup(cloneurl);
|
||||
/* we need to strdup the URL so that we can call curlx_free() on it later */
|
||||
*url = curlx_strdup(cloneurl);
|
||||
curl_free(cloneurl);
|
||||
if(!*url)
|
||||
goto clean;
|
||||
|
|
@ -209,7 +208,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
|
|||
result = CURLE_OK;
|
||||
|
||||
clean:
|
||||
free(gateway);
|
||||
curlx_free(gateway);
|
||||
curl_free(gwhost);
|
||||
curl_free(gwpath);
|
||||
curl_free(gwquery);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_libinfo.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* global variable definitions, for libcurl runtime info */
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
/* global variable declarations, for libcurl runtime info */
|
||||
|
||||
|
||||
extern curl_version_info_data *curlinfo;
|
||||
|
||||
extern const char * const *built_in_protos;
|
||||
|
|
|
|||
|
|
@ -42,13 +42,6 @@
|
|||
#include "tool_libinfo.h"
|
||||
#include "tool_stderr.h"
|
||||
|
||||
/*
|
||||
* This is low-level hard-hacking memory leak tracking and similar. Using
|
||||
* the library level code from this client-side is ugly, but we do this
|
||||
* anyway for convenience.
|
||||
*/
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef __VMS
|
||||
/*
|
||||
* vms_show is a global variable, used in main() as parameter for
|
||||
|
|
@ -121,7 +114,7 @@ static void memory_tracking_init(void)
|
|||
curl_free(env);
|
||||
curl_dbg_memdebug(fname);
|
||||
/* this weird stuff here is to make curl_free() get called before
|
||||
curl_dbg_memdebug() as otherwise memory tracking will log a free()
|
||||
curl_dbg_memdebug() as otherwise memory tracking will log a curlx_free()
|
||||
without an alloc! */
|
||||
}
|
||||
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
#include "tool_cb_prg.h"
|
||||
#include "terminal.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define WARN_PREFIX "Warning: "
|
||||
#define NOTE_PREFIX "Note: "
|
||||
#define ERROR_PREFIX "curl: "
|
||||
|
|
|
|||
|
|
@ -90,8 +90,6 @@
|
|||
CURL_EXTERN CURLcode curl_easy_perform_ev(CURL *easy);
|
||||
#endif
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef CURL_CA_EMBED
|
||||
#ifndef CURL_DECLARED_CURL_CA_EMBED
|
||||
#define CURL_DECLARED_CURL_CA_EMBED
|
||||
|
|
@ -204,7 +202,7 @@ static struct per_transfer *transfersl; /* last node */
|
|||
static CURLcode add_per_transfer(struct per_transfer **per)
|
||||
{
|
||||
struct per_transfer *p;
|
||||
p = calloc(1, sizeof(struct per_transfer));
|
||||
p = curlx_calloc(1, sizeof(struct per_transfer));
|
||||
if(!p)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
if(!transfers)
|
||||
|
|
@ -246,7 +244,7 @@ static struct per_transfer *del_per_transfer(struct per_transfer *per)
|
|||
else
|
||||
transfersl = p;
|
||||
|
||||
free(per);
|
||||
curlx_free(per);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
@ -770,10 +768,10 @@ skip:
|
|||
|
||||
curl_easy_cleanup(per->curl);
|
||||
if(outs->alloc_filename)
|
||||
free(outs->filename);
|
||||
free(per->url);
|
||||
free(per->outfile);
|
||||
free(per->uploadfile);
|
||||
curlx_free(outs->filename);
|
||||
curlx_free(per->url);
|
||||
curlx_free(per->outfile);
|
||||
curlx_free(per->uploadfile);
|
||||
curl_slist_free_all(per->hdrcbdata.headlist);
|
||||
per->hdrcbdata.headlist = NULL;
|
||||
return result;
|
||||
|
|
@ -785,7 +783,7 @@ static CURLcode set_cert_types(struct OperationConfig *config)
|
|||
/* Check if config->cert is a PKCS#11 URI and set the config->cert_type if
|
||||
* necessary */
|
||||
if(config->cert && !config->cert_type && is_pkcs11_uri(config->cert)) {
|
||||
config->cert_type = strdup("ENG");
|
||||
config->cert_type = curlx_strdup("ENG");
|
||||
if(!config->cert_type)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -793,7 +791,7 @@ static CURLcode set_cert_types(struct OperationConfig *config)
|
|||
/* Check if config->key is a PKCS#11 URI and set the config->key_type if
|
||||
* necessary */
|
||||
if(config->key && !config->key_type && is_pkcs11_uri(config->key)) {
|
||||
config->key_type = strdup("ENG");
|
||||
config->key_type = curlx_strdup("ENG");
|
||||
if(!config->key_type)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -802,7 +800,7 @@ static CURLcode set_cert_types(struct OperationConfig *config)
|
|||
* config->proxy_type if necessary */
|
||||
if(config->proxy_cert && !config->proxy_cert_type &&
|
||||
is_pkcs11_uri(config->proxy_cert)) {
|
||||
config->proxy_cert_type = strdup("ENG");
|
||||
config->proxy_cert_type = curlx_strdup("ENG");
|
||||
if(!config->proxy_cert_type)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -811,7 +809,7 @@ static CURLcode set_cert_types(struct OperationConfig *config)
|
|||
* config->proxy_key_type if necessary */
|
||||
if(config->proxy_key && !config->proxy_key_type &&
|
||||
is_pkcs11_uri(config->proxy_key)) {
|
||||
config->proxy_key_type = strdup("ENG");
|
||||
config->proxy_key_type = curlx_strdup("ENG");
|
||||
if(!config->proxy_key_type)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -844,7 +842,7 @@ static CURLcode append2query(struct OperationConfig *config,
|
|||
if(uerr)
|
||||
result = urlerr_cvt(uerr);
|
||||
else {
|
||||
free(per->url); /* free previous URL */
|
||||
curlx_free(per->url); /* free previous URL */
|
||||
per->url = updated; /* use our new URL instead! */
|
||||
}
|
||||
}
|
||||
|
|
@ -1022,7 +1020,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
|
|||
char *d = curl_maprintf("%s/%s", config->output_dir, per->outfile);
|
||||
if(!d)
|
||||
return CURLE_WRITE_ERROR;
|
||||
free(per->outfile);
|
||||
curlx_free(per->outfile);
|
||||
per->outfile = d;
|
||||
}
|
||||
/* Create the directory hierarchy, if not pre-existent to a multiple
|
||||
|
|
@ -1264,7 +1262,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
}
|
||||
per->etag_save = etag_first; /* copy the whole struct */
|
||||
if(state->uploadfile) {
|
||||
per->uploadfile = strdup(state->uploadfile);
|
||||
per->uploadfile = curlx_strdup(state->uploadfile);
|
||||
if(!per->uploadfile ||
|
||||
SetHTTPrequest(TOOL_HTTPREQ_PUT, &config->httpreq)) {
|
||||
tool_safefree(per->uploadfile);
|
||||
|
|
@ -1300,7 +1298,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
if(glob_inuse(&state->urlglob))
|
||||
result = glob_next_url(&per->url, &state->urlglob);
|
||||
else if(!state->urlidx) {
|
||||
per->url = strdup(u->url);
|
||||
per->url = curlx_strdup(u->url);
|
||||
if(!per->url)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -1312,7 +1310,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
return result;
|
||||
|
||||
if(u->outfile) {
|
||||
per->outfile = strdup(u->outfile);
|
||||
per->outfile = curlx_strdup(u->outfile);
|
||||
if(!per->outfile)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
@ -1586,7 +1584,7 @@ static struct contextuv *create_context(curl_socket_t sockfd,
|
|||
{
|
||||
struct contextuv *c;
|
||||
|
||||
c = (struct contextuv *) malloc(sizeof(*c));
|
||||
c = (struct contextuv *)curlx_malloc(sizeof(*c));
|
||||
|
||||
c->sockfd = sockfd;
|
||||
c->uv = uv;
|
||||
|
|
@ -1600,7 +1598,7 @@ static struct contextuv *create_context(curl_socket_t sockfd,
|
|||
static void close_cb(uv_handle_t *handle)
|
||||
{
|
||||
struct contextuv *c = (struct contextuv *) handle->data;
|
||||
free(c);
|
||||
curlx_free(c);
|
||||
}
|
||||
|
||||
static void destroy_context(struct contextuv *c)
|
||||
|
|
@ -2053,7 +2051,7 @@ static CURLcode cacertpaths(struct OperationConfig *config)
|
|||
|
||||
env = curl_getenv("CURL_CA_BUNDLE");
|
||||
if(env) {
|
||||
config->cacert = strdup(env);
|
||||
config->cacert = curlx_strdup(env);
|
||||
curl_free(env);
|
||||
if(!config->cacert) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -2063,7 +2061,7 @@ static CURLcode cacertpaths(struct OperationConfig *config)
|
|||
else {
|
||||
env = curl_getenv("SSL_CERT_DIR");
|
||||
if(env) {
|
||||
config->capath = strdup(env);
|
||||
config->capath = curlx_strdup(env);
|
||||
curl_free(env);
|
||||
if(!config->capath) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -2072,7 +2070,7 @@ static CURLcode cacertpaths(struct OperationConfig *config)
|
|||
}
|
||||
env = curl_getenv("SSL_CERT_FILE");
|
||||
if(env) {
|
||||
config->cacert = strdup(env);
|
||||
config->cacert = curlx_strdup(env);
|
||||
curl_free(env);
|
||||
if(!config->cacert) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -2088,7 +2086,7 @@ static CURLcode cacertpaths(struct OperationConfig *config)
|
|||
FILE *cafile = tool_execpath("curl-ca-bundle.crt", &cacert);
|
||||
if(cafile) {
|
||||
curlx_fclose(cafile);
|
||||
config->cacert = strdup(cacert);
|
||||
config->cacert = curlx_strdup(cacert);
|
||||
if(!config->cacert) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
goto fail;
|
||||
|
|
@ -2260,7 +2258,7 @@ CURLcode operate(int argc, argv_item_t argv[])
|
|||
if(found_curlrc) {
|
||||
/* After parse_args so notef knows the verbosity */
|
||||
notef("Read config file from '%s'", curlrc_path);
|
||||
free(curlrc_path);
|
||||
curlx_free(curlrc_path);
|
||||
}
|
||||
if(res) {
|
||||
result = CURLE_OK;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "tool_doswin.h"
|
||||
#include "tool_operhlp.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void clean_getout(struct OperationConfig *config)
|
||||
{
|
||||
|
|
@ -144,7 +143,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename)
|
|||
if(!newpath)
|
||||
goto fail;
|
||||
uerr = curl_url_set(uh, CURLUPART_PATH, newpath, 0);
|
||||
free(newpath);
|
||||
curlx_free(newpath);
|
||||
if(uerr) {
|
||||
result = urlerr_cvt(uerr);
|
||||
goto fail;
|
||||
|
|
@ -154,7 +153,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename)
|
|||
result = urlerr_cvt(uerr);
|
||||
goto fail;
|
||||
}
|
||||
free(*inurlp);
|
||||
curlx_free(*inurlp);
|
||||
*inurlp = newurl;
|
||||
result = CURLE_OK;
|
||||
}
|
||||
|
|
@ -206,11 +205,11 @@ CURLcode get_url_file_name(char **filename, const char *url)
|
|||
|
||||
if(pc) {
|
||||
/* duplicate the string beyond the slash */
|
||||
*filename = strdup(pc + 1);
|
||||
*filename = curlx_strdup(pc + 1);
|
||||
}
|
||||
else {
|
||||
/* no slash => empty string, use default */
|
||||
*filename = strdup("curl_response");
|
||||
*filename = curlx_strdup("curl_response");
|
||||
warnf("No remote filename, uses \"%s\"", *filename);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,9 @@
|
|||
#include "tool_util.h"
|
||||
#include "tool_version.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
struct getout *new_getout(struct OperationConfig *config)
|
||||
{
|
||||
struct getout *node = calloc(1, sizeof(struct getout));
|
||||
struct getout *node = curlx_calloc(1, sizeof(struct getout));
|
||||
struct getout *last = config->url_last;
|
||||
if(node) {
|
||||
static int outnum = 0;
|
||||
|
|
@ -401,7 +399,7 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
|
|||
|
||||
curlx_dyn_init(&obuf, MAX_PROTOSTRING);
|
||||
|
||||
protoset = malloc((proto_count + 1) * sizeof(*protoset));
|
||||
protoset = curlx_malloc((proto_count + 1) * sizeof(*protoset));
|
||||
if(!protoset)
|
||||
return PARAM_NO_MEM;
|
||||
|
||||
|
|
@ -499,14 +497,14 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
|
|||
for(proto = 0; protoset[proto] && !result; proto++)
|
||||
result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "",
|
||||
protoset[proto]);
|
||||
free((char *) protoset);
|
||||
curlx_free((char *)protoset);
|
||||
if(result)
|
||||
return PARAM_NO_MEM;
|
||||
if(!curlx_dyn_len(&obuf)) {
|
||||
curlx_dyn_free(&obuf);
|
||||
return PARAM_BAD_USE;
|
||||
}
|
||||
free(*ostr);
|
||||
curlx_free(*ostr);
|
||||
*ostr = curlx_dyn_ptr(&obuf);
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
|
@ -592,7 +590,7 @@ static CURLcode checkpasswd(const char *kind, /* for what purpose */
|
|||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
/* return the new string */
|
||||
free(*userpwd);
|
||||
curlx_free(*userpwd);
|
||||
*userpwd = curlx_dyn_ptr(&dyn);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include "tool_msgs.h"
|
||||
#include "tool_parsecfg.h"
|
||||
#include "tool_util.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* only acknowledge colon or equals as separators if the option was not
|
||||
specified with an initial dash! */
|
||||
|
|
@ -96,7 +95,7 @@ ParameterError parseconfig(const char *filename, int max_recursive,
|
|||
if(curlrc) {
|
||||
file = curlx_fopen(curlrc, FOPEN_READTEXT);
|
||||
if(!file) {
|
||||
free(curlrc);
|
||||
curlx_free(curlrc);
|
||||
return PARAM_READ_ERROR;
|
||||
}
|
||||
filename = pathalloc = curlrc;
|
||||
|
|
@ -266,11 +265,11 @@ ParameterError parseconfig(const char *filename, int max_recursive,
|
|||
errorf("cannot read config from '%s'", filename);
|
||||
|
||||
if(!err && resolved) {
|
||||
*resolved = strdup(filename);
|
||||
*resolved = curlx_strdup(filename);
|
||||
if(!*resolved)
|
||||
err = PARAM_NO_MEM;
|
||||
}
|
||||
free(pathalloc);
|
||||
curlx_free(pathalloc);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
#include "tool_msgs.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* Lookup tables for converting setopt values back to symbols */
|
||||
/* For enums, values may be in any order. */
|
||||
|
|
@ -385,7 +384,7 @@ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
|
|||
ret = easysrc_addf(&easysrc_data,
|
||||
"slist%d = curl_slist_append(slist%d, \"%s\");",
|
||||
*slistno, *slistno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -439,7 +438,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl,
|
|||
easysrc_addf(&easysrc_code,
|
||||
"curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
|
||||
mimeno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -452,7 +451,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl,
|
|||
ret = easysrc_addf(&easysrc_code,
|
||||
"curl_mime_filename(part%d, NULL);", mimeno);
|
||||
}
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -477,28 +476,28 @@ static CURLcode libcurl_generate_mime_part(CURL *curl,
|
|||
char *escaped = c_escape(part->encoder, ZERO_TERMINATED);
|
||||
ret = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");",
|
||||
mimeno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
|
||||
if(!ret && filename) {
|
||||
char *escaped = c_escape(filename, ZERO_TERMINATED);
|
||||
ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");",
|
||||
mimeno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->name) {
|
||||
char *escaped = c_escape(part->name, ZERO_TERMINATED);
|
||||
ret = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");",
|
||||
mimeno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->type) {
|
||||
char *escaped = c_escape(part->type, ZERO_TERMINATED);
|
||||
ret = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");",
|
||||
mimeno, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->headers) {
|
||||
|
|
@ -687,7 +686,7 @@ CURLcode tool_setopt_str(CURL *curl, struct OperationConfig *config,
|
|||
result = easysrc_addf(&easysrc_code,
|
||||
"curl_easy_setopt(hnd, %s, \"%s\");",
|
||||
name, escaped);
|
||||
free(escaped);
|
||||
curlx_free(escaped);
|
||||
}
|
||||
else
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ extern FILE *tool_stderr;
|
|||
|
||||
#ifndef HAVE_STRDUP
|
||||
#include "tool_strdup.h"
|
||||
#undef Curl_strdup
|
||||
#define Curl_strdup tool_strdup
|
||||
#endif
|
||||
|
||||
#ifndef tool_nop_stmt
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@
|
|||
#include "tool_ssls.h"
|
||||
#include "tool_parsecfg.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* The maximum line length for an ecoded session ticket */
|
||||
#define MAX_SSLS_LINE (64 * 1024)
|
||||
|
||||
|
|
@ -127,8 +125,8 @@ out:
|
|||
if(fp)
|
||||
curlx_fclose(fp);
|
||||
curlx_dyn_free(&buf);
|
||||
free(shmac);
|
||||
free(sdata);
|
||||
curlx_free(shmac);
|
||||
curlx_free(sdata);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +179,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr,
|
|||
out:
|
||||
if(r)
|
||||
warnf("Warning: error saving SSL session for '%s': %d", session_key, r);
|
||||
free(enc);
|
||||
curlx_free(enc);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "tool_setup.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
|
||||
CURLcode tool_ssls_load(struct OperationConfig *config,
|
||||
CURLSH *share, const char *filename);
|
||||
CURLcode tool_ssls_save(struct OperationConfig *config,
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@
|
|||
#include "tool_stderr.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
FILE *tool_stderr;
|
||||
|
||||
void tool_init_stderr(void)
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
#include "tool_strdup.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
char *strdup(const char *str)
|
||||
char *tool_strdup(const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char *newstr;
|
||||
|
|
@ -35,7 +34,7 @@ char *strdup(const char *str)
|
|||
|
||||
len = strlen(str) + 1;
|
||||
|
||||
newstr = malloc(len);
|
||||
newstr = curlx_malloc(len);
|
||||
if(!newstr)
|
||||
return (char *)NULL;
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ char *strdup(const char *str)
|
|||
|
||||
char *memdup0(const char *data, size_t len)
|
||||
{
|
||||
char *p = malloc(len + 1);
|
||||
char *p = curlx_malloc(len + 1);
|
||||
if(!p)
|
||||
return NULL;
|
||||
if(len)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
extern char *strdup(const char *str);
|
||||
extern char *tool_strdup(const char *str);
|
||||
#endif
|
||||
char *memdup0(const char *data, size_t len);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "tool_urlglob.h"
|
||||
#include "tool_vms.h"
|
||||
#include "tool_strdup.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static CURLcode globerror(struct URLGlob *glob, const char *err,
|
||||
size_t pos, CURLcode error)
|
||||
|
|
@ -45,7 +44,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
|
|||
pat->globindex = -1;
|
||||
pat->c.set.size = 0;
|
||||
pat->c.set.idx = 0;
|
||||
pat->c.set.elem = malloc(sizeof(char *));
|
||||
pat->c.set.elem = curlx_malloc(sizeof(char *));
|
||||
|
||||
if(!pat->c.set.elem)
|
||||
return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
|
||||
|
|
@ -137,10 +136,10 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp,
|
|||
|
||||
if(!palloc) {
|
||||
palloc = 5; /* a reasonable default */
|
||||
elem = malloc(palloc * sizeof(char *));
|
||||
elem = curlx_malloc(palloc * sizeof(char *));
|
||||
}
|
||||
else if(size >= palloc) {
|
||||
char **arr = realloc(elem, palloc * 2 * sizeof(char *));
|
||||
char **arr = curlx_realloc(elem, palloc * 2 * sizeof(char *));
|
||||
if(!arr) {
|
||||
result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
|
||||
goto error;
|
||||
|
|
@ -154,8 +153,8 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp,
|
|||
goto error;
|
||||
}
|
||||
|
||||
elem[size] =
|
||||
strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : "");
|
||||
elem[size] = curlx_strdup(curlx_dyn_ptr(&glob->buf) ?
|
||||
curlx_dyn_ptr(&glob->buf) : "");
|
||||
if(!elem[size]) {
|
||||
result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
|
||||
goto error;
|
||||
|
|
@ -206,7 +205,7 @@ error:
|
|||
for(i = 0; i < size; i++)
|
||||
tool_safefree(elem[i]);
|
||||
}
|
||||
free(elem);
|
||||
curlx_free(elem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +386,8 @@ static CURLcode add_glob(struct URLGlob *glob, size_t pos)
|
|||
struct URLPattern *np = NULL;
|
||||
glob->palloc *= 2;
|
||||
if(glob->pnum < 255) { /* avoid ridiculous amounts */
|
||||
np = realloc(glob->pattern, glob->palloc * sizeof(struct URLPattern));
|
||||
np = curlx_realloc(glob->pattern,
|
||||
glob->palloc * sizeof(struct URLPattern));
|
||||
if(!np)
|
||||
return globerror(glob, NULL, pos, CURLE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
|
@ -491,7 +491,7 @@ CURLcode glob_url(struct URLGlob *glob, char *url, curl_off_t *urlnum,
|
|||
|
||||
memset(glob, 0, sizeof(struct URLGlob));
|
||||
curlx_dyn_init(&glob->buf, 1024*1024);
|
||||
glob->pattern = malloc(2 * sizeof(struct URLPattern));
|
||||
glob->pattern = curlx_malloc(2 * sizeof(struct URLPattern));
|
||||
if(!glob->pattern)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
glob->palloc = 2;
|
||||
|
|
@ -617,7 +617,7 @@ CURLcode glob_next_url(char **globbed, struct URLGlob *glob)
|
|||
}
|
||||
|
||||
*globbed =
|
||||
strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : "");
|
||||
curlx_strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : "");
|
||||
if(!*globbed)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_util.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include "curlmsg_vms.h"
|
||||
#include "tool_vms.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void decc$__posix_exit(int __status);
|
||||
void decc$exit(int __status);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "tool_cfgable.h"
|
||||
#include "tool_writeout.h"
|
||||
#include "tool_writeout_json.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static int writeTime(FILE *stream, const struct writeoutvar *wovar,
|
||||
struct per_transfer *per, CURLcode per_result,
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
#include "tool_setup.h"
|
||||
#include "tool_xattr.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef USE_XATTR
|
||||
|
||||
/* mapping table of curl metadata to extended attribute names */
|
||||
|
|
|
|||
15
src/var.c
15
src/var.c
|
|
@ -33,7 +33,6 @@
|
|||
#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 */
|
||||
|
|
@ -45,8 +44,8 @@ void varcleanup(void)
|
|||
while(list) {
|
||||
struct tool_var *t = list;
|
||||
list = list->next;
|
||||
free(CURL_UNCONST(t->content));
|
||||
free(t);
|
||||
curlx_free(CURL_UNCONST(t->content));
|
||||
curlx_free(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +191,7 @@ static ParameterError varfunc(char *c, /* content */
|
|||
break;
|
||||
}
|
||||
if(alloc)
|
||||
free(c);
|
||||
curlx_free(c);
|
||||
|
||||
clen = curlx_dyn_len(out);
|
||||
c = memdup0(curlx_dyn_ptr(out), clen);
|
||||
|
|
@ -203,7 +202,7 @@ static ParameterError varfunc(char *c, /* content */
|
|||
alloc = TRUE;
|
||||
}
|
||||
if(alloc)
|
||||
free(c);
|
||||
curlx_free(c);
|
||||
if(err)
|
||||
curlx_dyn_free(out);
|
||||
return err;
|
||||
|
|
@ -359,7 +358,7 @@ static ParameterError addvariable(const char *name,
|
|||
if(check)
|
||||
notef("Overwriting variable '%s'", check->name);
|
||||
|
||||
p = calloc(1, sizeof(struct tool_var) + nlen);
|
||||
p = curlx_calloc(1, sizeof(struct tool_var) + nlen);
|
||||
if(p) {
|
||||
memcpy(p->name, name, nlen);
|
||||
/* the null termination byte is already present from above */
|
||||
|
|
@ -372,7 +371,7 @@ static ParameterError addvariable(const char *name,
|
|||
global->variables = p;
|
||||
return PARAM_OK;
|
||||
}
|
||||
free(p);
|
||||
curlx_free(p);
|
||||
}
|
||||
return PARAM_NO_MEM;
|
||||
}
|
||||
|
|
@ -496,7 +495,7 @@ ParameterError setvariable(const char *input)
|
|||
err = addvariable(name, nlen, content, clen, contalloc);
|
||||
if(err) {
|
||||
if(contalloc)
|
||||
free(content);
|
||||
curlx_free(content);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue