1

I just started to use Valgrind to check a C++ application for memory leaks. But every time the program tries to open an Sqlite3 database it terminates with a SIGSEGV. This does not happen when it is run without Valgrind.

The simplest program to demonstrate this is as follows

int main (int argc, char** argv) {
    sqlite3 *db = 0;
    sqlite3_open("/tmp/mydb.sqlite", &db);
    return 0;
}

Valgrind reports:

==29227== Jump to the invalid address stated on the next line
==29227==    at 0x0: ???
==29227==    by 0x48C606: mallocWithAlarm (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x477F71: sqlite3Malloc (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x4BD7F5: pthreadMutexAlloc (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x47740F: sqlite3_initialize (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x48929D: openDatabase (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x10014B507: main (in /usr/local/bin/outbound)
==29227==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==29227== 
==29227== 
==29227== Process terminating with default action of signal 11 (SIGSEGV)
==29227==  Bad permissions for mapped region at address 0x0
==29227==    at 0x0: ???
==29227==    by 0x48C606: mallocWithAlarm (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x477F71: sqlite3Malloc (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x4BD7F5: pthreadMutexAlloc (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x47740F: sqlite3_initialize (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x48929D: openDatabase (in /opt/local/lib/libsqlite3.0.8.6.dylib)
==29227==    by 0x10014B507: main (in /usr/local/bin/outbound)

What may cause this behaviour in Valgrind?

1 Answer 1

0

Try using a single HEAP object passed into sqlite3.

sqlite3_config (SQLITE_CONFIG_HEAP, malloc (1024*1024), 1024*1024, 64);

This allocates 1 MB of data, from a single "malloc" that valgrind will be happy with, with a minimum allocation size of 64 bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.