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);