diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-09-05 12:30:39 +0000 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2007-09-05 12:30:39 +0000 |
commit | 6b3803c386634f644879be4373a59194ce65f72b (patch) | |
tree | 55c9fc7929301e3ea00efa89a82ae6e01cbf13db /lib/conf-parse.y | |
parent | 6c4ea89ab95367ab8a9f3aec33b754cf0dff3b82 (diff) | |
download | lm-sensors-git-6b3803c386634f644879be4373a59194ce65f72b.tar.gz |
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/branches/lm-sensors-3.0.0@4768 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'lib/conf-parse.y')
-rw-r--r-- | lib/conf-parse.y | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/conf-parse.y b/lib/conf-parse.y index 30453eed..a4504a37 100644 --- a/lib/conf-parse.y +++ b/lib/conf-parse.y @@ -37,6 +37,8 @@ extern int sensors_yylineno; static void sensors_yyerror(const char *err); static sensors_expr *malloc_expr(void); +/* free_expr is defined in init.c */ +void free_expr(sensors_expr *expr); static sensors_chip *current_chip = NULL; @@ -77,15 +79,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 { @@ -152,7 +145,12 @@ bus_statement: BUS bus_id adapter_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; @@ -162,7 +160,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($3); + YYERROR; + } new_el.lineno = $1; new_el.name = $2; new_el.value = $3; @@ -172,7 +175,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; @@ -183,7 +192,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); |