From 84c55ed956cf38f4265f92f3d0b9016fe4cd9bec Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 24 Apr 2009 12:43:30 -0700 Subject: [PATCH] conf: remove some memory leaks, still have some more --- src/cconf.cc | 1 + src/common/ConfUtils.cc | 6 +++++- src/config.cc | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cconf.cc b/src/cconf.cc index ee19890971826..c7ed7a9a33dc4 100644 --- a/src/cconf.cc +++ b/src/cconf.cc @@ -111,6 +111,7 @@ int main(int argc, const char **argv) done_ok: cout << val << std::endl; + free(val); exit(0); } diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index 61439dac34421..6139076618e6b 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -564,12 +564,16 @@ bool ConfFile::_parse(char *filename, ConfSection **psection) printf("error parsing %s\n", cl->get_val()); } } else { - section->conf_map[cl->get_norm_var()] = cl; + char *norm_var = cl->get_norm_var(); + section->conf_map[norm_var] = cl; + free(norm_var); global_list.push_back(cl); section->conf_list.push_back(cl); } } else if (cl->get_section()) { section = _add_section(cl->get_section(), cl); + } else { + delete cl; } l = 0; break; diff --git a/src/config.cc b/src/config.cc index ec5831cf68058..9e1176c41793a 100644 --- a/src/config.cc +++ b/src/config.cc @@ -44,6 +44,20 @@ static bool show_config = false; static ConfFile *cf = NULL; static ExportControl *ec = NULL; +class ConfFileDestructor +{ +public: + ConfFileDestructor() {} + ~ConfFileDestructor() { + if (cf) { + delete cf; + cf = NULL; + } + } +}; + +static ConfFileDestructor cfd; + // page size crap, see page.h int _get_bits_of(int v) { int n = 0; -- 2.39.5