Changeset 5644

Show
Ignore:
Timestamp:
02/15/09 18:15:31 (3 years ago)
Author:
khali
Message:

Exit the configuration file parser as soon as we are done with it.
This makes the peak memory consumption significantly lower (-15% using
"sensors" in my tests).

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5640 r5644  
    1111              Fix memory leak in scanner when using flex 2.5.9 or later 
    1212              Report configuration file read errors 
     13              Exit the configuration file parser sooner 
    1314  lm_sensors.init: Support new format of /etc/sysconfig/lm_sensors (#2246) 
    1415                   Drop support for kernels 2.4 and earlier 
  • lm-sensors/trunk/lib/init.c

    r5638 r5644  
    6262} 
    6363 
     64static int parse_config(FILE *input) 
     65{ 
     66        int err; 
     67 
     68        if (sensors_scanner_init(input)) 
     69                return -SENSORS_ERR_PARSE; 
     70        err = sensors_parse(); 
     71        sensors_scanner_exit(); 
     72        if (err) 
     73                return -SENSORS_ERR_PARSE; 
     74 
     75        return 0; 
     76} 
     77 
    6478int sensors_init(FILE *input) 
    6579{ 
     
    7286                goto exit_cleanup; 
    7387 
    74         res = -SENSORS_ERR_PARSE; 
    7588        if (input) { 
    76                 if (sensors_scanner_init(input) || 
    77                     sensors_parse()) 
     89                res = parse_config(input); 
     90                if (res) 
    7891                        goto exit_cleanup; 
    7992        } else { 
     
    8396                        input = fopen(ALT_CONFIG_FILE, "r"); 
    8497                if (input) { 
    85                         if (sensors_scanner_init(input) || 
    86                             sensors_parse()) { 
    87                                 fclose(input); 
     98                        res = parse_config(input); 
     99                        fclose(input); 
     100                        if (res) 
    88101                                goto exit_cleanup; 
    89                         } 
    90                         fclose(input); 
     102 
    91103                } else if (errno != ENOENT) { 
    92104                        sensors_parse_error(strerror(errno), 0); 
     105                        res = -SENSORS_ERR_PARSE; 
    93106                        goto exit_cleanup; 
    94107                } 
     
    198211        int i; 
    199212 
    200         sensors_scanner_exit(); 
    201  
    202213        for (i = 0; i < sensors_proc_chips_count; i++) { 
    203214                free_chip_name(&sensors_proc_chips[i].chip);