libfstools: make sure file is closed on error
authorDaniel Golle <daniel@makrotopia.org>
Mon, 30 Aug 2021 19:11:30 +0000 (20:11 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 1 Nov 2021 16:13:29 +0000 (16:13 +0000)
Coverity CID: 1330286 Resource leak
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libfstools/common.c

index c4847766a0389a444b2dab39c2c14a0574587d97..8dc109537a195c0476a5c02cc2eb4391157ff477 100644 (file)
@@ -36,8 +36,10 @@ char
        if (!f)
                return NULL;
 
-       if (fgets(buf, bufsz, f) == NULL)
+       if (fgets(buf, bufsz, f) == NULL) {
+               fclose(f);
                return NULL;
+       }
 
        fclose(f);