Show
Ignore:
Timestamp:
09/06/07 14:22:59 (6 years ago)
Author:
khali
Message:

Fix memory leaks in the configuration file parser when a label, set,
compute or ignore statement is found before the first chip statement.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/conf-parse.y

    r4788 r4790  
    3030#include "conf.h" 
    3131#include "access.h" 
     32#include "init.h" 
    3233 
    3334static void sensors_yyerror(const char *err); 
     
    7374                                                  sizeof(sensors_chip_name)); 
    7475 
    75 /* YYERROR can only be called in rules, not in other functions, so this must 
    76    be a macro */ 
    77 #define check_current_chip()\ 
    78   do { if (! current_chip) {\ 
    79       sensors_yyerror("Label, Set or Compute statement before first chip statement");\ 
    80       YYERROR;\ 
    81     }\ 
    82   } while (0) 
    83  
    8476%} 
    8577 
     
    161153label_statement:          LABEL function_name string 
    162154                          { sensors_label new_el; 
    163                             check_current_chip(); 
     155                            if (!current_chip) { 
     156                              sensors_yyerror("Label statement before first chip statement"); 
     157                              free($2); 
     158                              free($3); 
     159                              YYERROR; 
     160                            } 
    164161                            new_el.lineno = $1; 
    165162                            new_el.name = $2; 
     
    171168set_statement:    SET function_name expression 
    172169                  { sensors_set new_el; 
    173                     check_current_chip(); 
     170                    if (!current_chip) { 
     171                      sensors_yyerror("Set statement before first chip statement"); 
     172                      free($2); 
     173                      free_expr($3); 
     174                      YYERROR; 
     175                    } 
    174176                    new_el.lineno = $1; 
    175177                    new_el.name = $2; 
     
    181183compute_statement:        COMPUTE function_name expression ',' expression 
    182184                          { sensors_compute new_el; 
    183                             check_current_chip(); 
     185                            if (!current_chip) { 
     186                              sensors_yyerror("Compute statement before first chip statement"); 
     187                              free($2); 
     188                              free_expr($3); 
     189                              free_expr($5); 
     190                              YYERROR; 
     191                            } 
    184192                            new_el.lineno = $1; 
    185193                            new_el.name = $2; 
     
    192200ignore_statement:       IGNORE function_name 
    193201                        { sensors_ignore new_el; 
    194                           check_current_chip(); 
     202                          if (!current_chip) { 
     203                            sensors_yyerror("Ignore statement before first chip statement"); 
     204                            free($2); 
     205                            YYERROR; 
     206                          } 
    195207                          new_el.lineno = $1; 
    196208                          new_el.name = $2;