aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-09-09 04:51:04 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-09-09 05:00:15 +0700
commitb89114b3faf1f91131c32792e2880e35d2131143 (patch)
tree387501d7964cbaa14182ec088ff560de460d7999
parent04f427170413b81801c1ff9445118d5795e609b1 (diff)
logging: fix memleak in log_target_create_file()
-rw-r--r--src/logging.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/logging.c b/src/logging.c
index 80ff72ca..db04cf7e 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -915,8 +915,10 @@ struct log_target *log_target_create_file(const char *fname)
target->type = LOG_TGT_TYPE_FILE;
target->tgt_file.out = fopen(fname, "a");
- if (!target->tgt_file.out)
+ if (!target->tgt_file.out) {
+ log_target_destroy(target);
return NULL;
+ }
target->output = _file_output;
@@ -966,6 +968,8 @@ void log_target_destroy(struct log_target *target)
#if (!EMBEDDED)
switch (target->type) {
case LOG_TGT_TYPE_FILE:
+ if (target->tgt_file.out == NULL)
+ break;
fclose(target->tgt_file.out);
target->tgt_file.out = NULL;
break;