Commit e8ea485
committed
sqlite: do not leave database open after failed open
When sqlite3_open_v2() fails, SQLite still assigns a database handle
in a "sick" state. Such a handle may only be used to retrieve the
error and must then be released with sqlite3_close(). Keeping it in
connection_ meant that after a failed open():
- isOpen incorrectly reported true,
- every method passed the "database is not open" check and called
SQLite APIs on the sick handle, which is an API misuse,
- registering a user-defined function leaked its user data in builds
with SQLITE_ENABLE_API_ARMOR, because SQLite rejects the call
before taking ownership of the user data,
- open() could not be retried since the database appeared open.
Close and reset the connection handle when open() fails at any point
so that the database remains closed and open() can be retried.
Fixes: #63831
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>1 parent da00166 commit e8ea485
2 files changed
Lines changed: 51 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
941 | 941 | | |
942 | 942 | | |
943 | 943 | | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
944 | 957 | | |
945 | 958 | | |
946 | 959 | | |
| |||
1003 | 1016 | | |
1004 | 1017 | | |
1005 | 1018 | | |
| 1019 | + | |
1006 | 1020 | | |
1007 | 1021 | | |
1008 | 1022 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
311 | 347 | | |
312 | 348 | | |
313 | 349 | | |
| |||
0 commit comments