diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2021-12-24 15:15:18 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2022-01-22 10:15:48 +0000 |
commit | 492ac453ab6b97280030fe6161dfcac3d84b36ce (patch) | |
tree | 9739745304fcca993ce9130435218c980291db07 /src/helper/log.c | |
parent | 1536e249f2c23399f3443f8351647ea3faa5112e (diff) | |
download | riscv-openocd-492ac453ab6b97280030fe6161dfcac3d84b36ce.zip riscv-openocd-492ac453ab6b97280030fe6161dfcac3d84b36ce.tar.gz riscv-openocd-492ac453ab6b97280030fe6161dfcac3d84b36ce.tar.bz2 |
log: fix memory leak when log to file is enabled
When log to file is enabled, the file is not closed by OpenOCD at
exit. This is reported by Valgrind as a memory leak that is still
reachable, as the internal buffers of 'FILE *log_output' are freed
by the automatic fclose() at exit.
Close the log file before exit.
Change-Id: Id472c0d04462035254a9b49ecb0a4037263c6f6f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6789
Tested-by: jenkins
Diffstat (limited to 'src/helper/log.c')
-rw-r--r-- | src/helper/log.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/helper/log.c b/src/helper/log.c index caa0a66..6865607 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -302,6 +302,15 @@ void log_init(void) start = last_time = timeval_ms(); } +void log_exit(void) +{ + if (log_output && log_output != stderr) { + /* Close log file, if it was open and wasn't stderr. */ + fclose(log_output); + } + log_output = NULL; +} + int set_log_output(struct command_context *cmd_ctx, FILE *output) { log_output = output; |