--- samba-4.14.0-orig/lib/tdb/common/open.c	tors jan. 21 14:20:40 2021
+++ samba-4.14.0/lib/tdb/common/open.c	ons mars 17 19:15:01 2021
@@ -127,19 +127,16 @@
 	/* Don't endian-convert the magic food! */
 	memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
 
-	if (!tdb_write_all(tdb->fd, newdb, size))
-		goto fail;
-
 	if (newdb->feature_flags & TDB_FEATURE_FLAG_MUTEX) {
 
 		/*
 		 * Now we init the mutex area
-		 * followed by a second header.
+		 * followed by the header.
 		 */
 
 		ret = ftruncate(
 			tdb->fd,
-			newdb->mutex_size + sizeof(struct tdb_header));
+			newdb->mutex_size /* + sizeof(struct tdb_header) */ );
 		if (ret == -1) {
 			goto fail;
 		}
@@ -149,7 +146,7 @@
 		}
 
 		/*
-		 * Write a second header behind the mutexes. That's the area
+		 * Write the header behind the mutexes. That's the area
 		 * that will be mmapp'ed.
 		 */
 		ret = lseek(tdb->fd, newdb->mutex_size, SEEK_SET);
@@ -156,11 +153,11 @@
 		if (ret == -1) {
 			goto fail;
 		}
-		if (!tdb_write_all(tdb->fd, newdb, size)) {
-			goto fail;
-		}
 	}
 
+	if (!tdb_write_all(tdb->fd, newdb, size)) {
+		goto fail;
+	}
 	ret = 0;
   fail:
 	SAFE_FREE(newdb);
