summaryrefslogtreecommitdiff
path: root/src/tool_setopt.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2012-03-17 20:55:15 +0100
committerYang Tse <yangsita@gmail.com>2012-03-17 20:55:15 +0100
commit804da995c5ed9df4d28690fba3d5256f45d75ef8 (patch)
treeef65dbecbab1e9e0ecf435919919dcb721d0f648 /src/tool_setopt.c
parentede9ad43fc014bec0c7bd79edad18668a03aea73 (diff)
downloadcurl-804da995c5ed9df4d28690fba3d5256f45d75ef8.tar.gz
tool_setopt.c: more OOM handling fixes
Diffstat (limited to 'src/tool_setopt.c')
-rw-r--r--src/tool_setopt.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index cd87ecedf..94e786f24 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -284,6 +284,7 @@ CURLcode tool_setopt_httppost(CURL *curl, struct Configurable *config,
struct curl_httppost *post)
{
CURLcode ret = CURLE_OK;
+ char *escaped = NULL;
bool skip = FALSE;
ret = curl_easy_setopt(curl, tag, post);
@@ -308,40 +309,39 @@ CURLcode tool_setopt_httppost(CURL *curl, struct Configurable *config,
for(pp=p; pp; pp=pp->more) {
/* May be several files uploaded for one name;
* these are linked through the 'more' pointer */
- char *e;
- e = c_escape(pp->contents);
- if(!e) {
+ Curl_safefree(escaped);
+ escaped = c_escape(pp->contents);
+ if(!escaped) {
ret = CURLE_OUT_OF_MEMORY;
goto nomem;
}
if(pp->flags & HTTPPOST_FILENAME) {
/* file upload as for -F @filename */
- DATA1(" CURLFORM_FILE, \"%s\",", e);
+ DATA1(" CURLFORM_FILE, \"%s\",", escaped);
}
else if(pp->flags & HTTPPOST_READFILE) {
/* content from file as for -F <filename */
- DATA1(" CURLFORM_FILECONTENT, \"%s\",", e);
+ DATA1(" CURLFORM_FILECONTENT, \"%s\",", escaped);
}
else
- DATA1(" CURLFORM_COPYCONTENTS, \"%s\",", e);
- free(e);
+ DATA1(" CURLFORM_COPYCONTENTS, \"%s\",", escaped);
if(pp->showfilename) {
- e = c_escape(pp->showfilename);
- if(!e) {
+ Curl_safefree(escaped);
+ escaped = c_escape(pp->showfilename);
+ if(!escaped) {
ret = CURLE_OUT_OF_MEMORY;
goto nomem;
}
- DATA1(" CURLFORM_FILENAME, \"%s\",", e);
- free(e);
+ DATA1(" CURLFORM_FILENAME, \"%s\",", escaped);
}
if(pp->contenttype) {
- e = c_escape(pp->contenttype);
- if(!e) {
+ Curl_safefree(escaped);
+ escaped = c_escape(pp->contenttype);
+ if(!escaped) {
ret = CURLE_OUT_OF_MEMORY;
goto nomem;
}
- DATA1(" CURLFORM_CONTENTTYPE, \"%s\",", e);
- free(e);
+ DATA1(" CURLFORM_CONTENTTYPE, \"%s\",", escaped);
}
}
DATA0(" CURLFORM_END);");
@@ -350,6 +350,7 @@ CURLcode tool_setopt_httppost(CURL *curl, struct Configurable *config,
}
nomem:
+ Curl_safefree(escaped);
return ret;
}
@@ -359,6 +360,7 @@ CURLcode tool_setopt_slist(CURL *curl, struct Configurable *config,
struct curl_slist *list)
{
CURLcode ret = CURLE_OK;
+ char *escaped = NULL;
bool skip = FALSE;
ret = curl_easy_setopt(curl, tag, list);
@@ -375,18 +377,19 @@ CURLcode tool_setopt_slist(CURL *curl, struct Configurable *config,
CLEAN1("curl_slist_free_all(slist%d);", i);
CLEAN1("slist%d = NULL;", i);
for(s=list; s; s=s->next) {
- char *e = c_escape(s->data);
- if(!e) {
+ Curl_safefree(escaped);
+ escaped = c_escape(s->data);
+ if(!escaped) {
ret = CURLE_OUT_OF_MEMORY;
goto nomem;
}
- DATA3("slist%d = curl_slist_append(slist%d, \"%s\");", i, i, e);
- free(e);
+ DATA3("slist%d = curl_slist_append(slist%d, \"%s\");", i, i, escaped);
}
CODE2("curl_easy_setopt(hnd, %s, slist%d);", name, i);
}
nomem:
+ Curl_safefree(escaped);
return ret;
}
@@ -401,6 +404,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
bool remark = FALSE;
bool skip = FALSE;
bool escape = FALSE;
+ char *escaped = NULL;
CURLcode ret = CURLE_OK;
va_start(arg, tag);
@@ -463,13 +467,12 @@ CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
REM2("%s set to a %s", name, value);
else {
if(escape) {
- char *escaped = c_escape(value);
+ escaped = c_escape(value);
if(!escaped) {
ret = CURLE_OUT_OF_MEMORY;
goto nomem;
}
CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped);
- free(escaped);
}
else
CODE2("curl_easy_setopt(hnd, %s, %s);", name, value);
@@ -477,6 +480,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
}
nomem:
+ Curl_safefree(escaped);
return ret;
}