diff options
author | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-03 08:05:44 +0200 |
---|---|---|
committer | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-05 09:52:39 +0200 |
commit | e67dd38588ee56fa59268205f60c9abb0da2fa83 (patch) | |
tree | 17339203439322ed5bce628a92488c600632e178 | |
parent | 2c9b75c7b206b47a06bfa096ace871b50c9e8787 (diff) |
energy_model: Close output file and error handling
make_energy_model_template() did not close the output stream, this
has been fixed. In addition, the (partial) output file is now deleted
in case of a failure.
Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
Reviewed-by: Larry Bassel <larry.bassel@linaro.org>
-rw-r--r-- | energy_model.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/energy_model.c b/energy_model.c index 143fc2b..93a2edc 100644 --- a/energy_model.c +++ b/energy_model.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <unistd.h> #include <errno.h> #include <assert.h> @@ -34,8 +35,11 @@ static int make_energy_model_template(struct program_options *options) init_cpu_topo_info(); read_sysfs_cpu_topo(); datas = idlestat_load(options->filename); - if (!datas) + if (!datas) { + fclose(f); + unlink(options->energy_model_filename); return -1; + } establish_idledata_to_topo(datas); list_for_each_entry(s_phy, &g_cpu_topo_list.physical_head, @@ -75,6 +79,8 @@ static int make_energy_model_template(struct program_options *options) fprintf(f, "\nwakeup\t\t?\t?\n"); cluster_number++; } + + fclose(f); return 0; } |