Whamcloud - gitweb
[COVERITY] Fix (error case) file handle leak in util/subst program
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 21 Mar 2007 21:19:55 +0000 (17:19 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 Mar 2007 21:19:55 +0000 (17:19 -0400)
Need to close old_f before returning since it had been successfully opened
before.

Coverity ID: 19: Resource Leak

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
util/ChangeLog
util/subst.c

index 1381c5b..e99d46c 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-21  Theodore Tso  <tytso@mit.edu>
+
+       * subst.c (compare_file): Close old FILE handle if the new FILE
+               handle open failed.
+
 2006-11-12  Theodore Tso  <tytso@mit.edu>
 
        * gen-tarball.in: Use E2FSPROGS_PKGVER to simplify script
index 445d318..fadf328 100644 (file)
@@ -279,8 +279,10 @@ static int compare_file(const char *outfn, const char *newfn)
        if (!old_f)
                return 0;
        new_f = fopen(newfn, "r");
-       if (!new_f)
+       if (!new_f) {
+               fclose(old_f);
                return 0;
+       }
 
        while (1) {
                oldcp = fgets(oldbuf, sizeof(oldbuf), old_f);