diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-12-06 08:25:56 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-12-06 09:59:38 +0100 |
commit | 75b31ce6267e42416a5a27fd1cf4eea60c420cb7 (patch) | |
tree | 8746f8f4d8513df829d752dd6dada1dd9cbddefa | |
parent | a40160aee83acae504fd4b30e39c28ff8dbab24c (diff) | |
download | curl-75b31ce6267e42416a5a27fd1cf4eea60c420cb7.tar.gz |
tool_operate: fix potential memory-leak
A 'CURLU *' would leak if url_proto() is called with no URL.
Detected by Coverity. CID 1494643.
Follow-up to 18270893abdb19
Closes #8098
-rw-r--r-- | src/tool_operate.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index d648dc054..44f01e94e 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -668,15 +668,17 @@ static long url_proto(char *url) { CURLU *uh = curl_url(); long proto = 0; - if(url) { - if(!curl_url_set(uh, CURLUPART_URL, url, - CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME)) { - char *schemep = NULL; - if(!curl_url_get(uh, CURLUPART_SCHEME, &schemep, - CURLU_DEFAULT_SCHEME) && - schemep) { - proto = scheme2protocol(schemep); - curl_free(schemep); + if(uh) { + if(url) { + if(!curl_url_set(uh, CURLUPART_URL, url, + CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME)) { + char *schemep = NULL; + if(!curl_url_get(uh, CURLUPART_SCHEME, &schemep, + CURLU_DEFAULT_SCHEME) && + schemep) { + proto = scheme2protocol(schemep); + curl_free(schemep); + } } } curl_url_cleanup(uh); |