tdb: Fix CID 1034841 Resource leak
authorVolker Lendecke <vl@samba.org>
Sun, 8 Mar 2015 19:18:21 +0000 (19:18 +0000)
committerVolker Lendecke <vl@samba.org>
Tue, 10 Mar 2015 20:48:04 +0000 (21:48 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ira Cooper <ira@samba.org>
lib/tdb/test/run-incompatible.c

index b8e95b5e77877e57de0115d072bf0d0b6c11a5a8..5f1b586f9cc3df0995a20655dda7dd3a99d9281e 100644 (file)
@@ -28,15 +28,17 @@ static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const ch
 static unsigned int hdr_rwlocks(const char *fname)
 {
        struct tdb_header hdr;
+       ssize_t nread;
 
        int fd = open(fname, O_RDONLY);
        if (fd == -1)
                return -1;
 
-       if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr))
-               return -1;
-
+       nread = read(fd, &hdr, sizeof(hdr));
        close(fd);
+       if (nread != sizeof(hdr)) {
+               return -1;
+       }
        return hdr.rwlocks;
 }