From 589fe9812e236c87babd0393637ec00ed036e0fe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 11 Nov 2010 09:36:25 +0100 Subject: [PATCH] tdb: set tdb->name early, as it's needed for tdb_name() tdb_name() might be used within the given log function, which might be called from within tdb_open_ex(). metze --- lib/tdb/common/open.c | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index f13df2c..adde90a 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -186,7 +186,11 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td #ifdef TDB_TRACE tdb->tracefd = -1; #endif - tdb->name = NULL; + /* + * set the name as the given string, so that tdb_name() will + * work in case of an error. + */ + tdb->name = name; tdb->map_ptr = NULL; tdb->flags = tdb_flags; tdb->open_flags = open_flags; @@ -197,6 +201,14 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td tdb->log.log_private = NULL; } + /* now make a copy of the name, as the caller memory might went away */ + if (!(tdb->name = (char *)strdup(name))) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't strdup(%s)\n", + name)); + errno = ENOMEM; + goto fail; + } + if (hash_fn) { tdb->hash_fn = hash_fn; hash_alg = "the user defined"; @@ -359,11 +371,6 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td goto fail; } - if (!(tdb->name = (char *)strdup(name))) { - errno = ENOMEM; - goto fail; - } - tdb->map_size = st.st_size; tdb->device = st.st_dev; tdb->inode = st.st_ino; -- 1.7.0.4