[syslog-ng] [PATCH (3.3)] value-pairs: Fix a small memory leak in the commandline parser.

Gergely Nagy algernon at balabit.hu
Sat Nov 12 10:29:24 CET 2011


Whenever we parse a command-line, we construct a new argv array, to
prepend a zeroth element for glibs option parser. We correctly free'd
it on the error path, but never on the success path.

This lead to a small memory leak every time
value_pairs_new_from_cmdline() was called (that is, at the moment,
each $(format-json) template function leaked a little bit).

This patch fixes this issue by modifying the error handling a little:
instead of freeing everything and returning NULL, we only free the
value-pairs structure, and set it to NULL. The rest of the freeing is
left up to the common parts afterwards, which now correctly frees the
constructed argv array too.

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 lib/value-pairs.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/value-pairs.c b/lib/value-pairs.c
index 803e14c..b5a95af 100644
--- a/lib/value-pairs.c
+++ b/lib/value-pairs.c
@@ -473,11 +473,10 @@ value_pairs_new_from_cmdline (GlobalConfig *cfg,
   if (!g_option_context_parse (ctx, &argc, &argv, error))
     {
       value_pairs_free (vp);
-      g_option_context_free (ctx);
-      g_free (argv);
-      return NULL;
+      vp = NULL;
     }
   g_option_context_free (ctx);
+  g_free (argv);
 
   return vp;
 }
-- 
1.7.7.2




More information about the syslog-ng mailing list