Earlier today, I ran Coverity on the latest HEAD of Wget. I've fixed some of the potential memory leaks that Coverity reported. Please take a look

--
Thanking You,
Darshit Shah
From e96c668c7b403e4ab6e54764284cfa209cc848e5 Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Sun, 1 Mar 2015 12:45:01 +0530
Subject: [PATCH 1/4] retr.c: Fix two memory leaks when proxy URL is bad

Reported by: Coverity bug 1188047
---
 src/retr.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/retr.c b/src/retr.c
index f12c50f..65d17b4 100644
--- a/src/retr.c
+++ b/src/retr.c
@@ -772,6 +772,8 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
                      proxy, error);
           xfree (url);
           xfree (error);
+          xfree (proxy);
+          iri_free (pi);
           RESTORE_METHOD;
           result = PROXERR;
           goto bail;
@@ -781,6 +783,8 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
           logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
           url_free (proxy_url);
           xfree (url);
+          xfree (proxy);
+          iri_free (pi);
           RESTORE_METHOD;
           result = PROXERR;
           goto bail;
-- 
2.3.1

From e2d674b17285be80033ae36d5c7f885c5bf46ab6 Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Sun, 1 Mar 2015 12:48:08 +0530
Subject: [PATCH 2/4] main.c: Fix two potential memory leaks

Reported by: Coverity bug 1188048
---
 src/main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c
index 7675455..b884c03 100644
--- a/src/main.c
+++ b/src/main.c
@@ -874,7 +874,10 @@ format_and_print_line (const char *prefix, const char *line,
   line_dup = xstrdup (line);
 
   if (printf ("%s", prefix) < 0)
-    return -1;
+    {
+      xfree (line_dup);
+      return -1;
+    }
 
   /* Wrap to new line after prefix. */
   remaining_chars = 0;
@@ -902,7 +905,10 @@ format_and_print_line (const char *prefix, const char *line,
     }
 
   if (printf ("\n") < 0)
-    return -1;
+    {
+      xfree (line_dup);
+      return -1;
+    }
 
   xfree (line_dup);
   return 0;
-- 
2.3.1

From c17dbd14639fce562b01986fbf1e739020994bd3 Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Sun, 1 Mar 2015 13:03:20 +0530
Subject: [PATCH 3/4] html-url.c: Fix potential memory leaks

Reported by: Coverity Bug 1188050
---
 src/html-url.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/html-url.c b/src/html-url.c
index 07c29bb..4fbcadf 100644
--- a/src/html-url.c
+++ b/src/html-url.c
@@ -303,6 +303,7 @@ append_url (const char *link_uri, int position, int size,
           logprintf (LOG_NOTQUIET,
                      _("%s: Cannot resolve incomplete link %s.\n"),
                      ctx->document_file, link_uri);
+          iri_free (iri);
           return NULL;
         }
 
@@ -311,6 +312,7 @@ append_url (const char *link_uri, int position, int size,
         {
           DEBUGP (("%s: link \"%s\" doesn't parse.\n",
                    ctx->document_file, link_uri));
+          iri_free (iri);
           return NULL;
         }
     }
@@ -334,6 +336,7 @@ append_url (const char *link_uri, int position, int size,
           DEBUGP (("%s: merged link \"%s\" doesn't parse.\n",
                    ctx->document_file, complete_uri));
           xfree (complete_uri);
+          iri_free (iri);
           return NULL;
         }
       xfree (complete_uri);
-- 
2.3.1

From c190a5d893fefc0a47bd0fce5fcf924308b4f4d0 Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Sun, 1 Mar 2015 13:06:11 +0530
Subject: [PATCH 4/4] retr.c: Fix memory leak in retrieve_from_file()

Reported by: Coverity Bug 1188045
---
 src/retr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/retr.c b/src/retr.c
index 65d17b4..82e9712 100644
--- a/src/retr.c
+++ b/src/retr.c
@@ -1023,6 +1023,7 @@ retrieve_from_file (const char *file, bool html, int *count)
           char *error = url_error (url, url_err);
           logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
           xfree (error);
+          iri_free (iri);
           return URLERROR;
         }
 
-- 
2.3.1

Attachment: pgpfakjVbZvoY.pgp
Description: PGP signature

Reply via email to