Otherwise tdb_name() can be NULL in log functions. And we might as
well allocate it with the tdb, as well.
tdb_bool_err berr;
enum TDB_ERROR ecode;
tdb_bool_err berr;
enum TDB_ERROR ecode;
- tdb = malloc(sizeof(*tdb));
+ tdb = malloc(sizeof(*tdb) + (name ? strlen(name) + 1 : 0));
if (!tdb) {
/* Can't log this */
errno = ENOMEM;
return NULL;
}
if (!tdb) {
/* Can't log this */
errno = ENOMEM;
return NULL;
}
+ /* Set name immediately for logging functions. */
+ if (name) {
+ tdb->name = strcpy((char *)(tdb + 1), name);
+ } else {
+ tdb->name = NULL;
+ }
tdb->direct_access = 0;
tdb->flags = tdb_flags;
tdb->log_fn = NULL;
tdb->direct_access = 0;
tdb->flags = tdb_flags;
tdb->log_fn = NULL;
#ifdef TDB_TRACE
close(tdb->tracefd);
#endif
#ifdef TDB_TRACE
close(tdb->tracefd);
#endif
- free(cast_const(char *, tdb->name));
if (tdb->file) {
tdb_lock_cleanup(tdb);
if (--tdb->file->refcnt == 0) {
if (tdb->file) {
tdb_lock_cleanup(tdb);
if (--tdb->file->refcnt == 0) {
else
tdb_munmap(tdb->file);
}
else
tdb_munmap(tdb->file);
}
- free(cast_const(char *, tdb->name));
if (tdb->file) {
struct tdb_file **i;
if (tdb->file) {
struct tdb_file **i;