Package: xapian-core / 1.4.3-2+deb9u3

fix-freelist-leaks.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--- a/backends/glass/glass_table.cc
+++ b/backends/glass/glass_table.cc
@@ -1640,6 +1640,7 @@
 	    /* writing - */
 	    SET_REVISION(p, revision_number + 1);
 	    C[0].set_n(free_list.get_block(this, block_size));
+	    C[0].rewrite = true;
 	}
     } else {
 	/* using a root block stored on disk */
@@ -1855,9 +1856,7 @@
 	}
     }
 
-    if (Btree_modified) {
-	faked_root_block = false;
-    }
+    faked_root_block = false;
 }
 
 void
@@ -1946,6 +1945,13 @@
     item_count =       root_info.get_num_entries();
     faked_root_block = root_info.get_root_is_fake();
     sequential =       root_info.get_sequential();
+    const string & fl_serialised = root_info.get_free_list();
+    if (!fl_serialised.empty()) {
+	if (!free_list.unpack(fl_serialised))
+	    throw Xapian::DatabaseCorruptError("Bad freelist metadata");
+    } else {
+	free_list.reset();
+    }
 
     Btree_modified = false;
 
--- a/tests/api_backend.cc
+++ b/tests/api_backend.cc
@@ -1555,3 +1555,23 @@
     TEST_EQUAL(mset.get_matches_estimated() % 10, 0);
     return true;
 }
+
+/// Regression test for glass bug fixed in 1.4.6 and 1.5.0.
+DEFINE_TESTCASE(nodocs1, transactions && !remote) {
+    {
+	Xapian::WritableDatabase db = get_named_writable_database("nodocs1");
+	db.set_metadata("foo", "bar");
+	db.commit();
+	Xapian::Document doc;
+	doc.add_term("baz");
+	db.add_document(doc);
+	db.commit();
+    }
+
+    size_t check_errors =
+	Xapian::Database::check(get_named_writable_database_path("nodocs1"),
+				Xapian::DBCHECK_SHOW_STATS, &tout);
+    TEST_EQUAL(check_errors, 0);
+
+    return true;
+}
--- a/tests/api_transdb.cc
+++ b/tests/api_transdb.cc
@@ -1,7 +1,7 @@
 /** @file api_transdb.cc
  * @brief tests requiring a database backend supporting transactions
  */
-/* Copyright (C) 2006,2009 Olly Betts
+/* Copyright (C) 2006,2009,2018 Olly Betts
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -126,3 +126,24 @@
 
     return true;
 }
+
+/// Regression test for glass bug fixed in 1.4.6 and 1.5.0.
+DEFINE_TESTCASE(canceltransaction3, transactions && !remote) {
+    {
+	Xapian::WritableDatabase db = get_named_writable_database("canceltransaction3");
+	db.begin_transaction();
+	Xapian::Document doc;
+	doc.add_term("baz");
+	db.add_document(doc);
+	db.cancel_transaction();
+	db.add_document(doc);
+	db.commit();
+    }
+
+    size_t check_errors =
+	Xapian::Database::check(get_named_writable_database_path("canceltransaction3"),
+				Xapian::DBCHECK_SHOW_STATS, &tout);
+    TEST_EQUAL(check_errors, 0);
+
+    return true;
+}