Changeset 4768

Show
Ignore:
Timestamp:
09/05/07 14:30:39 (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.

Location:
lm-sensors/branches/lm-sensors-3.0.0/lib
Files:
2 modified

Legend:

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

    r4756 r4768  
    3838static void sensors_yyerror(const char *err); 
    3939static sensors_expr *malloc_expr(void); 
     40/* free_expr is defined in init.c */ 
     41void free_expr(sensors_expr *expr); 
    4042 
    4143static sensors_chip *current_chip = NULL; 
     
    7880                                                  sizeof(sensors_chip_name)); 
    7981 
    80 /* YYERROR can only be called in rules, not in other functions, so this must 
    81    be a macro */ 
    82 #define check_current_chip()\ 
    83   do { if (! current_chip) {\ 
    84       sensors_yyerror("Label, Set or Compute statement before first chip statement");\ 
    85       YYERROR;\ 
    86     }\ 
    87   } while (0) 
    88  
    8982%} 
    9083 
     
    153146label_statement:          LABEL function_name string 
    154147                          { sensors_label new_el; 
    155                             check_current_chip(); 
     148                            if (!current_chip) { 
     149                              sensors_yyerror("Label statement before first chip statement"); 
     150                              free($2); 
     151                              free($3); 
     152                              YYERROR; 
     153                            } 
    156154                            new_el.lineno = $1; 
    157155                            new_el.name = $2; 
     
    163161set_statement:    SET function_name expression 
    164162                  { sensors_set new_el; 
    165                     check_current_chip(); 
     163                    if (!current_chip) { 
     164                      sensors_yyerror("Set statement before first chip statement"); 
     165                      free($2); 
     166                      free($3); 
     167                      YYERROR; 
     168                    } 
    166169                    new_el.lineno = $1; 
    167170                    new_el.name = $2; 
     
    173176compute_statement:        COMPUTE function_name expression ',' expression 
    174177                          { sensors_compute new_el; 
    175                             check_current_chip(); 
     178                            if (!current_chip) { 
     179                              sensors_yyerror("Compute statement before first chip statement"); 
     180                              free($2); 
     181                              free_expr($3); 
     182                              free_expr($5); 
     183                              YYERROR; 
     184                            } 
    176185                            new_el.lineno = $1; 
    177186                            new_el.name = $2; 
     
    184193ignore_statement:       IGNORE function_name 
    185194                        { sensors_ignore new_el; 
    186                           check_current_chip(); 
     195                          if (!current_chip) { 
     196                            sensors_yyerror("Ignore statement before first chip statement"); 
     197                            free($2); 
     198                            YYERROR; 
     199                          } 
    187200                          new_el.lineno = $1; 
    188201                          new_el.name = $2; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/init.c

    r4760 r4768  
    7272} 
    7373 
    74 static void free_expr(sensors_expr *expr) 
     74void free_expr(sensors_expr *expr) 
    7575{ 
    7676        if (expr->kind == sensors_kind_var)