From 556b03e4255ce57580d547cec930f3c7dbad0797 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 8 Feb 2009 12:00:24 +0000 Subject: [PATCH] Fix memory leak in scanner when using flex 2.5.9 or later. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5637 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/conf-lex.l | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES b/CHANGES index bfc7e96f..87d340ee 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ SVN-HEAD Detect excessive recursion depth during expression eval (#2365) Return a string rather than NULL for unknown errors Skip non-file sysfs entries for speed + Fix memory leak in scanner when using flex 2.5.9 or later lm_sensors.init: Support new format of /etc/sysconfig/lm_sensors (#2246) Drop support for kernels 2.4 and earlier lm_sensors.init.suse: Delete (actual SuSE script is much different) diff --git a/lib/conf-lex.l b/lib/conf-lex.l index afacefa7..0268f693 100644 --- a/lib/conf-lex.l +++ b/lib/conf-lex.l @@ -350,5 +350,15 @@ void sensors_scanner_exit(void) { sensors_yy_delete_buffer(scan_buf); scan_buf = (YY_BUFFER_STATE)0; + +/* As of flex 2.5.9, yylex_destroy() must be called when done with the + scaller, otherwise we'll leak memory. */ +#if defined(YY_FLEX_MAJOR_VERSION) && defined(YY_FLEX_MINOR_VERSION) && defined(YY_FLEX_SUBMINOR_VERSION) +#if YY_FLEX_MAJOR_VERSION > 2 || \ + (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION > 5 || \ + (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION >= 9))) + sensors_yylex_destroy(); +#endif +#endif }