[sqlite] Segment fault when running a query
Thank you very much for your help. Richard was correct in that it was a memory error earlier. /Fredrik 2016-02-04 16:53 GMT+01:00 Simon Slavin : > > On 3 Feb 2016, at 4:21pm, Fredrik Gustafsson wrote: > > > 223 rc = sqlite3_exec(db, "SELECT id, date, text FROM events > WHERE account_id=1 ORDER BY date DESC LIMIT 10" , NULL, NULL, &zErrMsg); > > To help debug this, insert two lines before this one. > > One checks to see that $zErrMsg is a real pointer, and points to a place > that your program can reach. It could be as simple as trying to write the > byte at that location. > > If that doesn't trigger a problem, try this one: > > Take the SQL command you're executing but hands it to sqlite3_prepare() > instead of sqlite3_exec(). This may give you an error status, or a > different crash which is easier to debug. > > Simon. > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >
[sqlite] Segment fault when running a query
On 3 Feb 2016, at 4:21pm, Fredrik Gustafsson wrote: > 223 rc = sqlite3_exec(db, "SELECT id, date, text FROM events WHERE > account_id=1 ORDER BY date DESC LIMIT 10" , NULL, NULL, &zErrMsg); To help debug this, insert two lines before this one. One checks to see that $zErrMsg is a real pointer, and points to a place that your program can reach. It could be as simple as trying to write the byte at that location. If that doesn't trigger a problem, try this one: Take the SQL command you're executing but hands it to sqlite3_prepare() instead of sqlite3_exec(). This may give you an error status, or a different crash which is easier to debug. Simon.
[sqlite] Segment fault when running a query
On 2/3/16, Fredrik Gustafsson wrote: > Hi, > I've a reproduceable error in my code, running a simple SQL question > gives me a segment fault. Running the program i gdb and doing backtrace > gives me this: > > (gdb) backtrace > #0 malloc_consolidate (av=av at entry=0x776be620 ) at > malloc.c:4149 > #1 0x77394ee8 in _int_malloc (av=0x776be620 , > bytes=3224) at malloc.c:3423 > #2 0x77397070 in __GI___libc_malloc (bytes=3224) at malloc.c:2891 ... > #8 0x77b87a66 in sqlite3_prepare_v2 () from > /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 > > Despite any errors in my code (which I'm sure there's), why does > sqlite3 crash this way? > Heap corruption. Something in your application has continued to use (and write on) malloc-ed memory after it was freed, or written past the end of one malloc-ed buffer into an adjacent one, or something else along those lines. SQLite probably had nothing to do with this, other than being the unlucky library that happened to be the first to stumble over the corrupted memory. Running your program using valgrind (http://www.valgrind.org/) will likely find the problem quickly. Valgrind might already be installed on your Linux machine, or if not it is a simple "apt-get" away. -- D. Richard Hipp drh at sqlite.org
[sqlite] Segment fault when running a query
Hi, I've a reproduceable error in my code, running a simple SQL question gives me a segment fault. Running the program i gdb and doing backtrace gives me this: (gdb) backtrace #0 malloc_consolidate (av=av at entry=0x776be620 ) at malloc.c:4149 #1 0x77394ee8 in _int_malloc (av=0x776be620 , bytes=3224) at malloc.c:3423 #2 0x77397070 in __GI___libc_malloc (bytes=3224) at malloc.c:2891 #3 0x77b53e77 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #4 0x77b2b12f in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #5 0x77b86cee in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #6 0x77b87442 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #7 0x77b877b7 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #8 0x77b87a66 in sqlite3_prepare_v2 () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #9 0x77b87b21 in sqlite3_exec () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #10 0x004079a1 in list_event (v=0x622d20, account_id=41, nbr_of_results=10) at event.c:223 #11 0x0040b5a8 in load_account (account_id=41, v=0x622d20) at account.c:603 #12 0x00401baa in tload_account () at t/test.c:201 #13 0x00402017 in taccount () at t/test.c:271 #14 0x0040369e in all_tests () at t/test.c:668 #15 0x0040374d in main (argc=1, argv=0x7fffe4a8) at t/test.c:683 The SQL in question is: SELECT id, date, text FROM events WHERE account_id=41 ORDER BY date DESC LIMIT 10 and it works fine running in the sqlite3 program (the query program that comes with sqlite3). Now the code above in list_event() has been working before but broke after a minor change that shouldn't effect sqlite3. I might have done that, however I don't expect this behaviour from sqlite3. The code that gives that error could be seen here: 221 if ( v == NULL) 222 flog("view is NULL\n\n"); 223 rc = sqlite3_exec(db, "SELECT id, date, text FROM events WHERE account_id=1 ORDER BY date DESC LIMIT 10" , NULL, NULL, &zErrMsg); 224 flog("query done\n"); 225 226 if (rc != SQLITE_OK) { 227 flog("ERROR: Could not list events, SQL error: %s\n\n%s", zErrMsg, q); 228 sqlite3_free(zErrMsg); 229 toret = -1; 230 } The callback function is never called. Despite any errors in my code (which I'm sure there's), why does sqlite3 crash this way? -- Fredrik Gustafsson phone: +46 733-608274 e-mail: iveqy at iveqy.com website: http://www.iveqy.com
[sqlite] Segment fault when running a query
Hi, I've a reproduceable error in my code, running a simple SQL question gives me a segment fault. Running the program i gdb and doing backtrace gives me this: (gdb) backtrace #0 malloc_consolidate (av=av at entry=0x776be620 ) at malloc.c:4149 #1 0x77394ee8 in _int_malloc (av=0x776be620 , bytes=3224) at malloc.c:3423 #2 0x77397070 in __GI___libc_malloc (bytes=3224) at malloc.c:2891 #3 0x77b53e77 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #4 0x77b2b12f in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #5 0x77b86cee in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #6 0x77b87442 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #7 0x77b877b7 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #8 0x77b87a66 in sqlite3_prepare_v2 () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #9 0x77b87b21 in sqlite3_exec () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #10 0x004079a1 in list_event (v=0x622d20, account_id=41, nbr_of_results=10) at event.c:223 #11 0x0040b5a8 in load_account (account_id=41, v=0x622d20) at account.c:603 #12 0x00401baa in tload_account () at t/test.c:201 #13 0x00402017 in taccount () at t/test.c:271 #14 0x0040369e in all_tests () at t/test.c:668 #15 0x0040374d in main (argc=1, argv=0x7fffe4a8) at t/test.c:683 The SQL in question is: SELECT id, date, text FROM events WHERE account_id=41 ORDER BY date DESC LIMIT 10 and it works fine running in the sqlite3 program (the query program that comes with sqlite3). Now the code above in list_event() has been working before but broke after a minor change that shouldn't effect sqlite3. I might have done that, however I don't expect this behaviour from sqlite3. The code that gives that error could be seen here: 221 if ( v == NULL) 222 flog("view is NULL\n\n"); 223 rc = sqlite3_exec(db, "SELECT id, date, text FROM events WHERE account_id=1 ORDER BY date DESC LIMIT 10" , NULL, NULL, &zErrMsg); 224 flog("query done\n"); 225 226 if (rc != SQLITE_OK) { 227 flog("ERROR: Could not list events, SQL error: %s\n\n%s", zErrMsg, q); 228 sqlite3_free(zErrMsg); 229 toret = -1; 230 } The callback function is never called. Despite any errors in my code (which I'm sure there's), why does sqlite3 crash this way? -- Fredrik Gustafsson phone: +46 733-608274 e-mail: iveqy at iveqy.com website: http://www.iveqy.com
[sqlite] Segment fault when running a query
Hi, I've a reproduceable error in my code, running a simple SQL question gives me a segment fault. Running the program i gdb and doing backtrace gives me this: (gdb) backtrace #0 malloc_consolidate (av=av at entry=0x776be620 ) at malloc.c:4149 #1 0x77394ee8 in _int_malloc (av=0x776be620 , bytes=3224) at malloc.c:3423 #2 0x77397070 in __GI___libc_malloc (bytes=3224) at malloc.c:2891 #3 0x77b53e77 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #4 0x77b2b12f in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #5 0x77b86cee in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #6 0x77b87442 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #7 0x77b877b7 in ?? () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #8 0x77b87a66 in sqlite3_prepare_v2 () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #9 0x77b87b21 in sqlite3_exec () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 #10 0x004079a1 in list_event (v=0x622d20, account_id=41, nbr_of_results=10) at event.c:223 #11 0x0040b5a8 in load_account (account_id=41, v=0x622d20) at account.c:603 #12 0x00401baa in tload_account () at t/test.c:201 #13 0x00402017 in taccount () at t/test.c:271 #14 0x0040369e in all_tests () at t/test.c:668 #15 0x0040374d in main (argc=1, argv=0x7fffe4a8) at t/test.c:683 The SQL in question is: SELECT id, date, text FROM events WHERE account_id=41 ORDER BY date DESC LIMIT 10 and it works fine running in the sqlite3 program (the query program that comes with sqlite3). Now the code above in list_event() has been working before but broke after a minor change that shouldn't effect sqlite3. I might have done that, however I don't expect this behaviour from sqlite3. The code that gives that error could be seen here: 221 if ( v == NULL) 222 flog("view is NULL\n\n"); 223 rc = sqlite3_exec(db, "SELECT id, date, text FROM events WHERE account_id=1 ORDER BY date DESC LIMIT 10" , NULL, NULL, &zErrMsg); 224 flog("query done\n"); 225 226 if (rc != SQLITE_OK) { 227 flog("ERROR: Could not list events, SQL error: %s\n\n%s", zErrMsg, q); 228 sqlite3_free(zErrMsg); 229 toret = -1; 230 } The callback function is never called. Despite any errors in my code (which I'm sure there's), why does sqlite3 crash this way? -- Fredrik Gustafsson phone: +46 733-608274 e-mail: iveqy at iveqy.com website: http://www.iveqy.com