Fix memory leaks in the configuration file parser when a label, set,

compute or ignore statement is found before the first chip statement.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4790 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-09-06 12:22:59 +00:00
1 parent b5b5507599
commit 44b77f38e4
3 files changed
+53 -14

No files matched your search

+25 -13
View File
@@ -29,6 +29,7 @@
#include "error.h"
#include "conf.h"
#include "access.h"
#include "init.h"
static void sensors_yyerror(const char *err);
static sensors_expr *malloc_expr(void);
@@ -72,15 +73,6 @@ static sensors_chip *current_chip = NULL;
&(list).fits_max, \
sizeof(sensors_chip_name));
/* YYERROR can only be called in rules, not in other functions, so this must
be a macro */
#define check_current_chip()\
do { if (! current_chip) {\
sensors_yyerror("Label, Set or Compute statement before first chip statement");\
YYERROR;\
}\
} while (0)
%}
%union {
@@ -160,7 +152,12 @@ busalgo_statement: BUS i2cbus_name adapter_name algorithm_name
label_statement: LABEL function_name string
{ sensors_label new_el;
check_current_chip();
if (!current_chip) {
sensors_yyerror("Label statement before first chip statement");
free($2);
free($3);
YYERROR;
}
new_el.lineno = $1;
new_el.name = $2;
new_el.value = $3;
@@ -170,7 +167,12 @@ label_statement: LABEL function_name string
set_statement: SET function_name expression
{ sensors_set new_el;
check_current_chip();
if (!current_chip) {
sensors_yyerror("Set statement before first chip statement");
free($2);
free_expr($3);
YYERROR;
}
new_el.lineno = $1;
new_el.name = $2;
new_el.value = $3;
@@ -180,7 +182,13 @@ set_statement: SET function_name expression
compute_statement: COMPUTE function_name expression ',' expression
{ sensors_compute new_el;
check_current_chip();
if (!current_chip) {
sensors_yyerror("Compute statement before first chip statement");
free($2);
free_expr($3);
free_expr($5);
YYERROR;
}
new_el.lineno = $1;
new_el.name = $2;
new_el.from_proc = $3;
@@ -191,7 +199,11 @@ compute_statement: COMPUTE function_name expression ',' expression
ignore_statement: IGNORE function_name
{ sensors_ignore new_el;
check_current_chip();
if (!current_chip) {
sensors_yyerror("Ignore statement before first chip statement");
free($2);
YYERROR;
}
new_el.lineno = $1;
new_el.name = $2;
ignore_add_el(&new_el);
+1 -1
View File
@@ -27,6 +27,7 @@
#include "conf.h"
#include "sysfs.h"
#include "scanner.h"
#include "init.h"
static void free_proc_chips_entry(sensors_proc_chips_entry entry);
static void free_chip_name(sensors_chip_name name);
@@ -36,7 +37,6 @@ static void free_label(sensors_label label);
static void free_set(sensors_set set);
static void free_compute(sensors_compute compute);
static void free_ignore(sensors_ignore ignore);
static void free_expr(sensors_expr *expr);
int sensors_init(FILE *input)
{
+27
View File
@@ -0,0 +1,27 @@
/*
init.h - Part of libsensors, a Linux library for reading sensor data.
Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
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_INIT_H
#define LIB_SENSORS_INIT_H
#include "data.h"
void free_expr(sensors_expr *expr);
#endif /* def LIB_SENSORS_INIT_H */