]> granicus.if.org Git - libnl/commitdiff
Fix file descriptor leak on error
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 27 Dec 2012 09:44:30 +0000 (10:44 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 27 Dec 2012 12:20:18 +0000 (13:20 +0100)
Detected by cppcheck

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
lib/utils.c

index b434bee1bb5c6ccf370b28e2900c44cd57a6c244..551118914d6d68e5bfea0530390fbc70bae08f82 100644 (file)
@@ -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);