summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-12-06 08:25:56 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-12-06 08:27:00 +0100
commitf0108b769d27e531ad4d1efdf8ba83d22caf9b9b (patch)
tree8746f8f4d8513df829d752dd6dada1dd9cbddefa
parenta40160aee83acae504fd4b30e39c28ff8dbab24c (diff)
downloadcurl-bagder/free-uh.tar.gz
tool_operate: fix potential memory-leakbagder/free-uh
A 'CURLU *' would leak if url_proto() is called with no URL. Detected by Coverity. CID 1494643. Follow-up to 18270893abdb19
-rw-r--r--src/tool_operate.c20
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);