[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Man-db-devel] [PATCH v2] Fix several resource and memory leaks
From: |
Nikola Forró |
Subject: |
[Man-db-devel] [PATCH v2] Fix several resource and memory leaks |
Date: |
Thu, 01 Nov 2018 13:26:19 +0100 |
Signed-off-by: Nikola Forró <address@hidden>
---
lib/decompress.c | 11 +++++++++--
lib/encodings.c | 4 +++-
src/man.c | 1 +
src/mandb.c | 19 ++++++++++++-------
src/whatis.c | 2 ++
5 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/lib/decompress.c b/lib/decompress.c
index 02b3ec05..7b746b74 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -49,11 +49,18 @@
static void decompress_zlib (void *data ATTRIBUTE_UNUSED)
{
gzFile zlibfile;
+ int fd;
- zlibfile = gzdopen (dup (STDIN_FILENO), "r");
- if (!zlibfile)
+ fd = dup (STDIN_FILENO);
+ if (fd < 0)
return;
+ zlibfile = gzdopen (fd, "r");
+ if (!zlibfile) {
+ close (fd);
+ return;
+ }
+
for (;;) {
char buffer[4096];
int r = gzread (zlibfile, 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..d7a432a8 100644
--- a/src/man.c
+++ b/src/man.c
@@ -1458,6 +1458,7 @@ static pipeline *make_roff_command (const char *dir,
const char *file,
pipeline_command (p, cmd);
}
+ free (fmt_prog);
free (page_encoding);
return p;
}
diff --git a/src/mandb.c b/src/mandb.c
index 78f6d1a6..fcef6d00 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -558,7 +558,7 @@ static int process_manpath (const char *manpath, int
global_manpath,
struct tried_catdirs_entry *tried;
struct stat st;
int run_mandb = 0;
- struct dbpaths *dbpaths;
+ struct dbpaths *dbpaths = NULL;
int amount = 0;
if (global_manpath) { /* system db */
@@ -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))
- return 0;
+ if (stat (manpath, &st) < 0 || !S_ISDIR (st.st_mode)) {
+ amount = 0;
+ goto out;
+ }
tried->seen = 1;
if (single_filename) {
@@ -618,10 +620,13 @@ static int process_manpath (const char *manpath, int
global_manpath,
#endif /* MAN_OWNER */
out:
- cleanup_sigsafe (dbpaths);
- pop_cleanup (cleanup_sigsafe, dbpaths);
- cleanup (dbpaths);
- pop_cleanup (cleanup, dbpaths);
+ if (dbpaths) {
+ cleanup_sigsafe (dbpaths);
+ pop_cleanup (cleanup_sigsafe, dbpaths);
+ cleanup (dbpaths);
+ pop_cleanup (cleanup, dbpaths);
+ }
+
free (database);
database = NULL;
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
- [Man-db-devel] [PATCH v2] Fix several resource and memory leaks,
Nikola Forró <=