While working on Serval 0.08 I have been working with SQLite3 for the first time.
I had the following fairly innocent query causing SQLite to report an "out of memory" error:
int count=sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE id='%s' AND datavalid<>0;",hash);
After spending a bit of time hunting everywhere to find where I could possibly have leaked enough RAM for SQLite3 to get upset, I finally realised that the column datavalid did not exist in the FILES table. I had meant to update the CREATE TABLE statement, but obviously hadn't gotten around to it.
I updated the CREATE TABLE statement to include a definition for the datavalid column, and the "out of memory" errors are now a thing of the past.
I can only guess that somewhere in SQLite3 when it tries to find the column, it gets a NULL pointer returned, which some other part of itself then interprets as a failure to allocate memory to retrieve the column, rather than the failure of the column itself to exist.