src/db.c: fix: make sure the database is properly closed
Thanks to ASAN, it was discovered that some part of heap
is not released on exit:
==19736==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 94616 byte(s) in 214 object(s) allocated from:
#0 0x4e05c6 (/home/wmn/osmocom/osmo-hlr/src/osmo-hlr+0x4e05c6)
#1 0x7f9b01061dc6 (/usr/lib/x86_64-linux-gnu/libsqlite3.so.0+0x33dc6)
Indirect leak of 1160 byte(s) in 1 object(s) allocated from:
#0 0x4e097d (/home/wmn/osmocom/osmo-hlr/src/osmo-hlr+0x4e097d)
#1 0x7f9b01061d58 (/usr/lib/x86_64-linux-gnu/libsqlite3.so.0+0x33d58)
SUMMARY: AddressSanitizer: 95776 byte(s) leaked in 215 allocation(s).
After a long investigation, it was figured out that *sqlite never
closes the database* due to 'unfinalized statements or unfinished
backups'.
The problem was in db_bootstrap(), where several statements were
prepared, but not finalized in loop. This was also the reason of
*.db-shm / *.db-wal files remaining after the program is closed,
and the reason of the following message
db.c:77 (283) recovered 18 frames from WAL file *.db-wal
Let's fix this and stop ignoring the result of sqlite3_close().
Change-Id: Ibe620d7723b1947d4f60f820bd18435ad0193112
Related: OS#3434
1 file changed