]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Close manifest files after reading/writing them
authorRamiro Polla <ramiro.polla@gmail.com>
Thu, 15 Jul 2010 17:54:11 +0000 (14:54 -0300)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 16 Jul 2010 13:59:59 +0000 (15:59 +0200)
manifest.c

index c759f1cb81b9691f15155709d5a7fe32d4b69cfb..388000e5c112fc9c6bddeb2eb4af84820d63803f 100644 (file)
@@ -634,10 +634,17 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash,
                mf = read_manifest(f1);
                if (!mf) {
                        cc_log("Failed to read manifest file");
+                       gzclose(f1);
                        goto out;
                }
        }
 
+       if (f1) {
+               gzclose(f1);
+       } else {
+               close(fd1);
+       }
+
        if (mf->n_objects > MAX_MANIFEST_ENTRIES) {
                /*
                 * Normally, there shouldn't be many object entries in the
@@ -673,6 +680,8 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash,
 
        add_object_entry(mf, object_hash, included_files);
        if (write_manifest(f2, mf)) {
+               gzclose(f2);
+               f2 = NULL;
                unlink(manifest_path);
                if (rename(tmp_file, manifest_path) == 0) {
                        ret = 1;
@@ -696,8 +705,5 @@ out:
        if (f2) {
                gzclose(f2);
        }
-       if (f1) {
-               gzclose(f1);
-       }
        return ret;
 }