diff options
author | Stefan Sperling <ssperling@sysmocom.de> | 2018-11-27 11:47:41 +0100 |
---|---|---|
committer | Stefan Sperling <ssperling@sysmocom.de> | 2018-11-27 15:59:46 +0100 |
commit | 908d3cc921f52783f7ddd3d301b19bf11a3d79e7 (patch) | |
tree | 3d44039b891ae06bf1f543022c8ed7b60aaf32c5 | |
parent | ac0061a30fb491ac704546997dd7814844edfce3 (diff) |
fix file descriptor leak in osysmon_file_read
Don't forget to close the file which was opened at the
beginning of this function's scope. Found by Coverity.
Change-Id: Ie1b5734748438c6d785cd96dfa9af6303cd102da
Related: CID#189756
-rw-r--r-- | osysmon_file.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/osysmon_file.c b/osysmon_file.c index 6f826b4..3a228fa 100644 --- a/osysmon_file.c +++ b/osysmon_file.c @@ -77,7 +77,7 @@ static void osysmon_file_destroy(struct osysmon_file *of) static void osysmon_file_read(struct osysmon_file *of, struct value_node *parent) { char buf[512]; - char *nl; + char *s, *nl; FILE *f; f = fopen(of->cfg.path, "r"); @@ -85,7 +85,9 @@ static void osysmon_file_read(struct osysmon_file *of, struct value_node *parent value_node_add(parent, parent, of->cfg.name, "<NOTFOUND>"); return; } - if (fgets(buf, sizeof(buf), f) == NULL) { + s = fgets(buf, sizeof(buf), f); + fclose(f); + if (s == NULL) { value_node_add(parent, parent, of->cfg.name, "<EMPTY>"); return; } |