summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Jarosch <thomas.jarosch@intra2net.com>2012-12-27 10:44:30 +0100
committerThomas Graf <tgraf@suug.ch>2012-12-27 13:20:18 +0100
commit69719322546f8550208a7ad984f704259c9091cb (patch)
treea897923c936e9480269ce6a55d7c0875ff903a77
parentde213328f810afbf39380561855507c8b8c78e08 (diff)
downloadlibnl-69719322546f8550208a7ad984f704259c9091cb.tar.gz
Fix file descriptor leak on error
Detected by cppcheck Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r--lib/utils.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/utils.c b/lib/utils.c
index b434bee..5511189 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -84,24 +84,32 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
continue;
num = strtol(buf, &end, 0);
- if (end == buf)
+ if (end == buf) {
+ fclose(fd);
return -NLE_INVAL;
+ }
- if (num == LONG_MIN || num == LONG_MAX)
+ if (num == LONG_MIN || num == LONG_MAX) {
+ fclose(fd);
return -NLE_RANGE;
+ }
while (*end == ' ' || *end == '\t')
end++;
goodlen = strcspn(end, "#\r\n\t ");
- if (goodlen == 0)
+ if (goodlen == 0) {
+ fclose(fd);
return -NLE_INVAL;
+ }
end[goodlen] = '\0';
err = cb(num, end);
- if (err < 0)
+ if (err < 0) {
+ fclose(fd);
return err;
+ }
}
fclose(fd);