From 43c59765e1405d80938ae5b7dc80244de20bdc9f Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 16 Sep 2011 00:57:54 +0200 Subject: main.c: convert GetStr() into a macro to ease leak debugging --- src/main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 38e50987b..3161cb38a 100644 --- a/src/main.c +++ b/src/main.c @@ -980,6 +980,7 @@ static int parseconfig(const char *filename, static char *my_get_line(FILE *fp); static int create_dir_hierarchy(const char *outfile, FILE *errors); +#if 0 static void GetStr(char **string, const char *value) { @@ -987,6 +988,17 @@ static void GetStr(char **string, if(value) *string = strdup(value); } +#else +#define GetStr(str,val) \ +do { \ + if(*(str)) { \ + free(*(str)); \ + *(str) = NULL; \ + } \ + if((val)) \ + *(str) = strdup((val)); \ +} WHILE_FALSE +#endif static void clean_getout(struct Configurable *config) { @@ -3084,7 +3096,8 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ "Appending one for you!\n"); off = curlx_strtoofft(nextarg, NULL, 10); snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off); - GetStr(&config->range, buffer); + Curl_safefree(config->range); + config->range = strdup(buffer); } { /* byte range requested */ @@ -3172,7 +3185,8 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ case 'v': if(toggle) { /* the '%' thing here will cause the trace get sent to stderr */ - GetStr(&config->trace_dump, (char *)"%"); + Curl_safefree(config->trace_dump); + config->trace_dump = strdup("%"); if(config->tracetype && (config->tracetype != TRACE_PLAIN)) warnf(config, "-v, --verbose overrides an earlier trace/verbose option\n"); -- cgit v1.2.3