Previous leak fix caused multiple sensors_init() calls to break.

This patch fixes that by managing the scanner buffers manually.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3300 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Mark M. Hoffman committed 2006-05-20 15:24:37 +00:00
1 parent 54423af70d
commit 4d2c4fd212
3 files changed
+58 -4

No files matched your search

+26 -3
View File
@@ -25,6 +25,7 @@
#include "data.h"
#include "conf-parse.h"
#include "error.h"
#include "scanner.h"
static int buffer_count;
static int buffer_max;
@@ -48,6 +49,7 @@ char sensors_lex_error[100];
/* Scanner for configuration files */
%option nodefault
%option noyywrap
%option yylineno
%option nounput
@@ -269,9 +271,30 @@ OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7])
%%
int sensors_yywrap(void)
/*
Do the buffer handling manually. This allows us to scan as many
config files as we need to, while cleaning up properly after each
one. The "BEGIN(0)" line ensures that we start in the default state,
even if e.g. the previous config file was syntactically broken.
Returns 0 if successful, !0 otherwise.
*/
static YY_BUFFER_STATE scan_buf = (YY_BUFFER_STATE)0;
int sensors_scanner_init(FILE *input)
{
yy_delete_buffer(YY_CURRENT_BUFFER);
return 1;
BEGIN(0);
if (!(scan_buf = sensors_yy_create_buffer(input, YY_BUF_SIZE)))
return -1;
sensors_yy_switch_to_buffer(scan_buf);
return 0;
}
void sensors_scanner_exit(void)
{
sensors_yy_delete_buffer(scan_buf);
scan_buf = (YY_BUFFER_STATE)0;
}
+5 -1
View File
@@ -26,6 +26,7 @@
#include "access.h"
#include "conf.h"
#include "sysfs.h"
#include "scanner.h"
static void free_proc_chips_entry(sensors_proc_chips_entry entry);
static void free_chip_name(sensors_chip_name name);
@@ -48,7 +49,8 @@ int sensors_init(FILE *input)
if ((res = sensors_read_proc_chips()) || (res = sensors_read_proc_bus()))
return res;
}
sensors_yyin = input;
if ((res = sensors_scanner_init(input)))
return -SENSORS_ERR_PARSE;
if ((res = sensors_yyparse()))
return -SENSORS_ERR_PARSE;
if ((res = sensors_substitute_busses()));
@@ -60,6 +62,8 @@ void sensors_cleanup(void)
{
int i;
sensors_scanner_exit();
for (i = 0; i < sensors_proc_chips_count; i++)
free_proc_chips_entry(sensors_proc_chips[i]);
free(sensors_proc_chips);
+27
View File
@@ -0,0 +1,27 @@
/*
scanner.h - Part of libsensors, a Linux library for reading sensor data.
Copyright (c) 2006 Mark M. Hoffman <mhoffman@lightlink.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LIB_SENSORS_SCANNER_H
#define LIB_SENSORS_SCANNER_H
extern int sensors_scanner_init(FILE *input);
extern void sensors_scanner_exit(void);
#endif