]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: fix potential memory-leak
authorDaniel Stenberg <daniel@haxx.se>
Mon, 6 Dec 2021 07:25:56 +0000 (08:25 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 6 Dec 2021 08:59:38 +0000 (09:59 +0100)
A 'CURLU *' would leak if url_proto() is called with no URL.

Detected by Coverity. CID 1494643.
Follow-up to 18270893abdb19
Closes #8098

src/tool_operate.c

index d648dc054c706c4dd4b9cfadbe0c97d8b72e61d7..44f01e94ea1359763f7f6ff89e0a051f64045909 100644 (file)
@@ -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);