Skip to content

Commit 6f44af6

Browse files
committed
fix race condition indicated by valgrind
1 parent 29029e8 commit 6f44af6

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/SQLiteNestedVFS.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -690,22 +690,24 @@ class InnerDatabaseFile : public SQLiteVFS::File {
690690
upsert->bind(3, job->meta2);
691691
}
692692
upsert->bind(4, job->pageno);
693-
StatementResetter resetter(*upsert);
694-
if (upsert->exec() != 1) {
695-
throw std::runtime_error("unexpected result from page upsert");
696-
}
697693

698-
if (page1plain_ && job->pageno == 1) {
699-
// see ReadPlainPage1() above. When we write page 1, cc its first 100 bytes into a
700-
// special row with pageno = -100.
701-
upsert->reset();
702-
upsert->bindNoCopy(1, job->encoded_page,
703-
std::min(job->encoded_page_size, size_t(100)));
704-
upsert->bind(2, job->meta1);
705-
upsert->bind(3, job->meta2);
706-
upsert->bind(4, (sqlite_int64)-100);
694+
{
695+
StatementResetter resetter(*upsert);
707696
if (upsert->exec() != 1) {
708-
throw std::runtime_error("unexpected result from header upsert");
697+
throw std::runtime_error("unexpected result from page upsert");
698+
}
699+
700+
if (page1plain_ && job->pageno == 1) {
701+
// see ReadPlainPage1() above. When we write page 1, cc its first 100 bytes
702+
// into a special row with pageno = -100.
703+
upsert->reset();
704+
upsert->bindNoCopy(1, job->encoded_page,
705+
std::min(job->encoded_page_size, size_t(100)));
706+
// keep meta1 & meta2 bindings, if any
707+
upsert->bind(4, (sqlite_int64)-100);
708+
if (upsert->exec() != 1) {
709+
throw std::runtime_error("unexpected result from header upsert");
710+
}
709711
}
710712
}
711713

0 commit comments

Comments
 (0)