Fix up some memory leaks in !THD_SUCCESS branches

In various THD_SUCCESS failure paths memory is being leaked, so
free them to stop the daemon leaking excessively.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
cthd_engine: guard against negative array indexes

cthd_engine::get_sensor() and cthd_engine::get_zone() should
be checking for negative array indexes to avoid array indexing
underflow.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
csys_fs: fix fd leaks in lseek error return path

Fix fd leaks in the lseek error return paths of
csys_fs::write() and csys_fs::read()

Signed-off-by: Colin Ian King <colin.king@canonical.com>
cthd_engine: remove redundant reads of thermal zone type files

takeover_thermal_control() and giveup_thermal_control() both
contain redundant reads of the thermal zone type fields, so remove
this code.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
thd_engine.cpp: use %u intead of %d for signed integers

Replace %d with %u in format string for signed integers

Signed-off-by: Colin Ian King <colin.king@canonical.com>
thd_model.cpp: use correct integer format specifiers

Use %d for signed integers

Signed-off-by: Colin Ian King <colin.king@canonical.com>
thd_model.cpp: remove ununsed variable 'file'

variable 'file' is not used in store_set_point() so remove it

Signed-off-by: Colin Ian King <colin.king@canonical.com>
thd_parse.cpp: use correct unsigned integer format specifiers

Use %u for unsigned integers

Signed-off-by: Colin Ian King <colin.king@canonical.com>
thd_engine.cpp: check fcntl non-blocking error return

fcntl can possibly fail, so it is probably wise to sanity check for
failed O_NONBLOCK fcntl requests.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
fix leak of trip_ptr in read_trip_points

trip_ptr is being leaked in read_trip_points, ensure we
free it before we return

Signed-off-by: Colin Ian King <colin.king@canonical.com>
ensure device_path is null terminated

In the unlikely event that path exceeds the length of device_path
we should null terminate is as strncpy() will not do that for us
with an overly long path

Signed-off-by: Colin Ian King <colin.king@canonical.com>
get_preference_cstr: return C string allocated on heap

The original code returned a C string that was effectively
destroyed when exiting the scope.  Best to dup this C string
so it is on the heap and use and free it by the caller.

Signed-off-by: Colin Ian King <colin.king@canonical.com>