]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/open.c
Import 855391c1e37012b0d6c673a304bb8da8a1efcd72 from ctdb:
[ccan] / ccan / tdb / open.c
index 8b9776864a6729a5a85bcfe470c73c709db45364..77c6936fc2f5bac28b6c421f3d61f730cba71129 100644 (file)
@@ -164,6 +164,9 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
 
        tdb_io_init(tdb);
        tdb->fd = -1;
+#ifdef TDB_TRACE
+       tdb->tracefd = -1;
+#endif
        tdb->name = NULL;
        tdb->map_ptr = NULL;
        tdb->flags = tdb_flags;
@@ -208,10 +211,6 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
                        goto fail;
                }
-#ifdef TDB_TRACE
-               /* All tracing will fail.  That's ok. */
-               tdb->tracefd = -1;
-#endif
                goto internal;
        }
 
@@ -403,8 +402,10 @@ int tdb_close(struct tdb_context *tdb)
                        tdb_munmap(tdb);
        }
        SAFE_FREE(tdb->name);
-       if (tdb->fd != -1)
+       if (tdb->fd != -1) {
                ret = close(tdb->fd);
+               tdb->fd = -1;
+       }
        SAFE_FREE(tdb->lockrecs);
 
        /* Remove from contexts list */