Changeset 5738

Show
Ignore:
Timestamp:
06/20/09 11:53:23 (6 years ago)
Author:
khali
Message:

sensord, sensors: Fix a memory leak when one or more chip names are
provided on the command line.

Location:
lm-sensors/branches/lm-sensors-2.10
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-2.10/CHANGES

    r5707 r5738  
    88  Module i2c-piix4: ATI SB800 is not actually supported 
    99  Module it87: Properly decode -128 degrees C (2.6 backport) 
     10  Program sensord: Fix a memory leak when a chip name is provided 
     11  Program sensors: Fix a memory leak when a chip name is provided 
    1012  Program sensors-detect: Fix detection of older DS1621 
    1113 
  • lm-sensors/branches/lm-sensors-2.10/prog/sensord/args.c

    r4821 r5738  
    299299      if ((err = sensors_parse_chip_name (arg, chipNames + i))) { 
    300300        fprintf (stderr, "Invalid chip name `%s': %s\n", arg, sensors_strerror (err)); 
     301        for (-- i; i >= 0; -- i) 
     302          free (chipNames[i].prefix); 
    301303        return -1; 
    302304      } 
     
    306308  return 0; 
    307309} 
     310 
     311void 
     312freeChips 
     313() { 
     314  int i; 
     315  for (i = 0; i < numChipNames; ++ i) 
     316    free (chipNames[i].prefix); 
     317} 
  • lm-sensors/branches/lm-sensors-2.10/prog/sensord/sensord.c

    r5572 r5738  
    200200   
    201201  if (initLib () || 
    202       loadLib ()) 
    203     exit (EXIT_FAILURE); 
     202      loadLib ()) { 
     203    freeChips (); 
     204    exit (EXIT_FAILURE); 
     205  } 
    204206 
    205207  if (isDaemon) 
     
    226228  } 
    227229   
     230  freeChips (); 
    228231  if (unloadLib ()) 
    229232    exit (EXIT_FAILURE); 
  • lm-sensors/branches/lm-sensors-2.10/prog/sensord/sensord.h

    r4810 r5738  
    4747extern int parseArgs (int argc, char **argv); 
    4848extern int parseChips (int argc, char **argv); 
     49extern void freeChips (); 
    4950 
    5051/* from lib.c */ 
  • lm-sensors/branches/lm-sensors-2.10/prog/sensors/main.c

    r5364 r5738  
    9393} 
    9494 
     95void free_chip_names() 
     96{ 
     97  int i; 
     98 
     99  for (i = 0; i < chips_count; i++) 
     100    free(chips[i].prefix); 
     101} 
     102 
    95103/* This examines global var config_file, and leaves the name there too.  
    96104   It also opens config_file. */ 
     
    106114    fprintf(stderr, "Could not open config file\n"); 
    107115    perror(config_file_name); 
     116    free_chip_names(); 
    108117    exit(1); 
    109118  } 
     
    222231      if ((res = sensors_parse_chip_name(argv[i],chips+chips_count))) { 
    223232        fprintf(stderr,"Parse error in chip name `%s'\n",argv[i]); 
     233        free_chip_names(); 
    224234        print_short_help(); 
    225235        exit(1); 
    226236      } else if (++chips_count == CHIPS_MAX) { 
    227237        fprintf(stderr,"Too many chips on command line!\n"); 
     238        free_chip_names(); 
    228239        exit(1); 
    229240      } 
     
    239250              "For 2.6 kernels, make sure you have mounted sysfs and libsensors\n" 
    240251              "was compiled with sysfs support!\n"); 
     252    free_chip_names(); 
    241253    sensors_cleanup(); 
    242254    exit(1); 
     
    247259 
    248260  if(do_the_real_work(&error)) { 
     261    free_chip_names(); 
    249262    sensors_cleanup(); 
    250263    exit(error); 
     
    257270    else 
    258271            fprintf(stderr,"Specified sensor(s) not found!\n"); 
     272    free_chip_names(); 
    259273    sensors_cleanup(); 
    260274    exit(1);