diff --git a/src/gallium/auxiliary/hud/hud_sensors_temp.c b/src/gallium/auxiliary/hud/hud_sensors_temp.c index e41b847..765d08f 100644 --- a/src/gallium/auxiliary/hud/hud_sensors_temp.c +++ b/src/gallium/auxiliary/hud/hud_sensors_temp.c @@ -68,6 +68,7 @@ struct sensors_temp_info sensors_chip_name *chip; const sensors_feature *feature; double current, min, max, critical; + int users; }; static double @@ -193,11 +194,17 @@ static void free_query_data(void *p) { struct sensors_temp_info *sti = (struct sensors_temp_info *) p; - list_del(&sti->list); - if (sti->chip) - sensors_free_chip_name(sti->chip); - FREE(sti); - sensors_cleanup(); + if (--sti->users == 0) { + list_del(&sti->list); + gsensors_temp_count--; + if (sti->chip) + sensors_free_chip_name(sti->chip); + FREE(sti); + } + + /* Destroy sensor singleton when after all refs released. */ + if (!gsensors_temp_count) + sensors_cleanup(); } /** @@ -234,6 +241,7 @@ hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name, sti->mode == SENSORS_POWER_CURRENT ? "Pow" : sti->mode == SENSORS_TEMP_CRITICAL ? "Crit" : "Unkn"); + sti->users++; gr->query_data = sti; gr->query_new_value = query_sti_load;