From 5c6dae44aa0ad7e607e3dcb9126d4e3d59870d02 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 17 Nov 2012 05:58:59 -0700 Subject: [PATCH] Various memory leaks in configuration parsing This lot are all small issues derived from allocating new memory and assigning to a pointer already pointing at previous allocation, or passing xstrdup() output to a caller which does not directly hold the passed memory. Both cases will disappear once we clean up teh string handlign in Squid but for now these still need fixing to avoid leaking memory. Detected by Coverity Scan. Issues 740430, 740432, 740439. --- src/adaptation/icap/Options.cc | 7 +++++-- src/cache_cf.cc | 1 + src/main.cc | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/adaptation/icap/Options.cc b/src/adaptation/icap/Options.cc index c792735107..219589c1de 100644 --- a/src/adaptation/icap/Options.cc +++ b/src/adaptation/icap/Options.cc @@ -205,8 +205,11 @@ void Adaptation::Icap::Options::TransferList::parse(const String &buf, bool &fou while (strListGetItem(&buf, ',', &item, &ilen, &pos)) { if (ilen == 1 && *item == '*') foundStar = true; - else - add(xstrndup(item, ilen+1)); + else { + const char *tmp = xstrndup(item, ilen+1); + add(tmp); + xfree(tmp); + } } } diff --git a/src/cache_cf.cc b/src/cache_cf.cc index ed1f2192ce..0464f7685c 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -594,6 +594,7 @@ parseOneConfigFile(const char *file_name, unsigned int depth) cfg_filename = orig_cfg_filename; config_lineno = orig_config_lineno; + xfree(tmp_line); return err_count; } diff --git a/src/main.cc b/src/main.cc index 544fe2838c..128c8da2eb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -541,6 +541,7 @@ mainParseOptions(int argc, char *argv[]) /** \par l * Stores the syslog facility name in global opt_syslog_facility * then performs actions for -s option. */ + xfree(opt_syslog_facility); // ignore any previous options sent opt_syslog_facility = xstrdup(optarg); case 's': -- 2.47.3