sensord: Fix memory leaks revealed by valgrind
PATCH 1/3 sensord: Fix memory leaks revealed by valgrind
The leak in daemonize() is harmless, we're about to exit anyway. Fix it still to make valgrind happy.
The leak in do_features() is real, as the function is called periodically by the daemon, for all actions. If the intervals at set low and the system has many sensors, the leak could be significant, maybe 150 kB/day.
--- prog/sensord/sense.c | 22 +++++++++++++--------- prog/sensord/sensord.c | 6 +++++- 2 files changed, 18 insertions(+), 10 deletions(-)
prog/sensord/sensord.c +5 -1
@@ -204,7 +204,11 @@ static void daemonize(void) }else if (pid !=0 ) {fprintf (file,"%d\n" , pid);fclose (file); -unloadLib (); + +freeChips (); +if (unloadLib ()) +exit (EXIT_FAILURE ); +exit (EXIT_SUCCESS ); }
prog/sensord/sense.c +13 -9
@@ -132,14 +132,7 @@ static int do_features(const sensors_chi const FeatureDescriptor *feature, int action) { char *label; -int alrm, beep; - - label =sensors_get_label (chip, feature->feature); -if (!label) { -sensorLog (LOG_ERR ,"Error getting sensor label: %s/%s" , - chip->prefix, feature->feature->name); -return -1 ; - } +int alrm, beep, ret; alrm =get_flag (chip, feature->alarmNumber);if (alrm =-1 )
@@ -151,7 +144,18 @@ static int do_features(const sensors_chiif (beep =-1 )return -1 ; -return get_features (chip, feature, action, label, alrm, beep); + label =sensors_get_label (chip, feature->feature); +if (!label) { +sensorLog (LOG_ERR ,"Error getting sensor label: %s/%s" , + chip->prefix, feature->feature->name); +return -1 ; + } + + ret =get_features (chip, feature, action, label, alrm, beep); + +free (label); + +return ret; } static int doKnownChip(const sensors_chip_name *chip,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 12 lines · Jean Delvare
The leak in
daemonize()is harmless, we're about to exit anyway. Fix it still to make valgrind happy.The leak in
do_features()is real, as the function is called periodically by the daemon, for all actions. If the intervals at set low and the system has many sensors, the leak could be significant, maybe 150 kB/day.--- prog/sensord/sense.c | 22 +++++++++++++--------- prog/sensord/sensord.c | 6 +++++- 2 files changed, 18 insertions(+), 10 deletions(-)
Nice catch series looks good.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors