diff options
author | Yang Tse <yangsita@gmail.com> | 2011-10-05 15:06:26 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2011-10-05 15:06:26 +0200 |
commit | 5bf0d74120a92fb834b0d13098c0b5e93249a84f (patch) | |
tree | 3a89799eee7cc7f3d7e50b7598735b080444307f /src/tool_operhlp.c | |
parent | fd87d9d2b9e8a5ebb8e49f0a5611e40289fa9f05 (diff) | |
download | curl-5bf0d74120a92fb834b0d13098c0b5e93249a84f.tar.gz |
curl tool: OOM handling fixes
Diffstat (limited to 'src/tool_operhlp.c')
-rw-r--r-- | src/tool_operhlp.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index 1a72035f7..5a6a670f9 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -152,14 +152,17 @@ char *add_file_name_to_url(CURL *curl, char *url, const char *filename) } /* Extracts the name portion of the URL. - * Returns a heap-allocated string, or NULL if no name part + * Returns a pointer to a heap-allocated string or NULL if + * no name part, at location indicated by first argument. */ -char *get_url_file_name(const char *url) +CURLcode get_url_file_name(char **filename, const char *url) { - char *fn = NULL; + const char *pc; + + *filename = NULL; /* Find and get the remote file name */ - const char *pc = strstr(url, "://"); + pc = strstr(url, "://"); if(pc) pc += 3; else @@ -169,9 +172,13 @@ char *get_url_file_name(const char *url) if(pc) { /* duplicate the string beyond the slash */ pc++; - fn = *pc ? strdup(pc): NULL; + if(*pc) { + *filename = strdup(pc); + if(!*filename) + return CURLE_OUT_OF_MEMORY; + } } - return fn; + return CURLE_OK; } /* |