man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH] Fix several resource and memory leaks


From: Nikola Forró
Subject: [Man-db-devel] [PATCH] Fix several resource and memory leaks
Date: Thu, 01 Nov 2018 12:07:39 +0100

Signed-off-by: Nikola Forró <address@hidden>
---
 lib/decompress.c | 8 ++++++--
 lib/encodings.c  | 4 +++-
 src/man.c        | 3 +++
 src/mandb.c      | 4 +++-
 src/whatis.c     | 2 ++
 5 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/decompress.c b/lib/decompress.c
index 02b3ec05..ae364843 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -49,10 +49,14 @@
 static void decompress_zlib (void *data ATTRIBUTE_UNUSED)
 {
        gzFile zlibfile;
+       int fd;
 
-       zlibfile = gzdopen (dup (STDIN_FILENO), "r");
-       if (!zlibfile)
+       zlibfile = gzdopen (fd = dup (STDIN_FILENO), "r");
+       if (!zlibfile) {
+               if (fd >= 0)
+                       close (fd);
                return;
+       }
 
        for (;;) {
                char buffer[4096];
diff --git a/lib/encodings.c b/lib/encodings.c
index d982827d..ec8fb6bc 100644
--- a/lib/encodings.c
+++ b/lib/encodings.c
@@ -605,8 +605,10 @@ char *find_charset_locale (const char *charset)
                                if (setlocale (LC_CTYPE, locale)) {
                                        free (encoding);
                                        goto out;
-                               } else
+                               } else {
+                                       free (locale);
                                        locale = NULL;
+                               }
                        }
                        free (encoding);
                }
diff --git a/src/man.c b/src/man.c
index 5eacab69..ba5771f0 100644
--- a/src/man.c
+++ b/src/man.c
@@ -1458,6 +1458,9 @@ static pipeline *make_roff_command (const char *dir, 
const char *file,
                pipeline_command (p, cmd);
        }
 
+       if (fmt_prog)
+               free (fmt_prog);
+
        free (page_encoding);
        return p;
 }
diff --git a/src/mandb.c b/src/mandb.c
index 78f6d1a6..81f35a0d 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -574,8 +574,10 @@ static int process_manpath (const char *manpath, int 
global_manpath,
        tried->seen = 0;
        hashtable_install (tried_catdirs, catpath, strlen (catpath), tried);
 
-       if (stat (manpath, &st) < 0 || !S_ISDIR (st.st_mode))
+       if (stat (manpath, &st) < 0 || !S_ISDIR (st.st_mode)) {
+               free (catpath);
                return 0;
+       }
        tried->seen = 1;
 
        if (single_filename) {
diff --git a/src/whatis.c b/src/whatis.c
index 0dd7be12..b4e9551d 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -829,6 +829,8 @@ nextpage:
                free_mandata_elements (&info);
        }
 
+       free (found_here);
+
        for (i = 0; i < num_pages; ++i)
                free (lowpages[i]);
        free (lowpages);
-- 
2.17.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]