1
From 30e5450ec47bded0f48f1097515e2ce9f3e05e05 Mon Sep 17 00:00:00 2001
2
From: Colin Ian King <colin.king@canonical.com>
3
Date: Mon, 10 Mar 2014 09:31:19 +0000
4
Subject: [PATCH 17/28] Fix up some memory leaks in !THD_SUCCESS branches
6
In various THD_SUCCESS failure paths memory is being leaked, so
7
free them to stop the daemon leaking excessively.
9
Signed-off-by: Colin Ian King <colin.king@canonical.com>
11
src/thd_engine.cpp | 12 +++++++++---
12
src/thd_engine_default.cpp | 12 ++++++++++--
13
2 files changed, 19 insertions(+), 5 deletions(-)
15
diff --git a/src/thd_engine.cpp b/src/thd_engine.cpp
16
index 87e70e0..f00c616 100644
17
--- a/src/thd_engine.cpp
18
+++ b/src/thd_engine.cpp
19
@@ -609,8 +609,10 @@ void cthd_engine::thd_read_default_thermal_sensors() {
20
i = atoi(entry->d_name + strlen("thermal_zone"));
21
cthd_sensor *sensor = new cthd_sensor(i,
22
base_path + entry->d_name + "/", "");
23
- if (sensor->sensor_update() != THD_SUCCESS)
24
+ if (sensor->sensor_update() != THD_SUCCESS) {
28
sensors.push_back(sensor);
31
@@ -635,8 +637,10 @@ void cthd_engine::thd_read_default_thermal_zones() {
32
i = atoi(entry->d_name + strlen("thermal_zone"));
33
cthd_sysfs_zone *zone = new cthd_sysfs_zone(i,
34
"/sys/class/thermal/thermal_zone");
35
- if (zone->zone_update() != THD_SUCCESS)
36
+ if (zone->zone_update() != THD_SUCCESS) {
40
if (control_mode == EXCLUSIVE)
41
zone->set_zone_active();
42
zones.push_back(zone);
43
@@ -664,8 +668,10 @@ void cthd_engine::thd_read_default_cooling_devices() {
44
i = atoi(entry->d_name + strlen("cooling_device"));
45
cthd_sysfs_cdev *cdev = new cthd_sysfs_cdev(i,
46
"/sys/class/thermal/");
47
- if (cdev->update() != THD_SUCCESS)
48
+ if (cdev->update() != THD_SUCCESS) {
52
cdevs.push_back(cdev);
55
diff --git a/src/thd_engine_default.cpp b/src/thd_engine_default.cpp
56
index 43e23c6..b75d899 100644
57
--- a/src/thd_engine_default.cpp
58
+++ b/src/thd_engine_default.cpp
59
@@ -107,8 +107,10 @@ int cthd_engine_default::read_thermal_sensors() {
60
base_path + entry->d_name + "/"
61
+ temp_input_str.str(),
62
temp_input_str.str(), SENSOR_TYPE_RAW);
63
- if (sensor->sensor_update() != THD_SUCCESS)
64
+ if (sensor->sensor_update() != THD_SUCCESS) {
68
sensors.push_back(sensor);
71
@@ -127,8 +129,10 @@ int cthd_engine_default::read_thermal_sensors() {
72
cthd_sensor *sensor = new cthd_sensor(index,
73
"/sys/class/hwmon/hwmon0/temp1_input", "hwmon",
75
- if (sensor->sensor_update() != THD_SUCCESS)
76
+ if (sensor->sensor_update() != THD_SUCCESS) {
80
sensors.push_back(sensor);
83
@@ -197,6 +201,8 @@ int cthd_engine_default::read_thermal_zones() {
84
zones.push_back(zone);
86
cpu_zone_created = true;
92
@@ -214,6 +220,8 @@ int cthd_engine_default::read_thermal_zones() {
93
zones.push_back(zone);
95
cpu_zone_created = true;
100
if (!cpu_zone_created) {