SQLite crashes in sqlite3DbMallocRaw

5

We are seeing this crash report very frequently in our iOS-targeted database framework.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000001a
Triggered by Thread:  3

Thread 3 name:
Thread 3 Crashed:
0   libsqlite3.dylib                0x3a1fb150 sqlite3DbMallocRaw + 60 (sqlite3.c:19398)
1   libsqlite3.dylib                0x3a1cf950 yy_reduce + 19164 (sqlite3.c:19499)
2   libsqlite3.dylib                0x3a1cadbc sqlite3Parser + 252 (sqlite3.c:116602)
3   libsqlite3.dylib                0x3a1ca558 sqlite3RunParser + 260 (sqlite3.c:117427)
4   libsqlite3.dylib                0x3a1c9f18 sqlite3Prepare + 400 (sqlite3.c:99613)
5   libsqlite3.dylib                0x3a1c9c68 sqlite3LockAndPrepare + 140 (sqlite3.c:99705)
6   libsqlite3.dylib                0x3a204746 sqlite3_prepare_v2 + 26 (sqlite3.c:99784)

It always crashes in prepare. Our code for prepare is nothing special.

- (DBStatement *)_prepareStatement:(NSString *)sql error:(NSError **)error
{
    if (sql == nil) {
        return nil;
    }

    const char *sqlCStr = [sql UTF8String];
    sqlite3_stmt *stmt;
    int result = sqlite3_prepare_v2(_db, sqlCStr, -1, &stmt, NULL);
    if (result == SQLITE_OK) {
        // create statement object
    }

    // ...

    return statement;
}

Has anyone seen this before? What causes this crash? We are checking if the SQL string is nil before trying to execute prepare, so I don't think it's a NULL pointer dereference with in our code.

ios
database
sqlite
asked on Stack Overflow Apr 19, 2013 by dkaranovich

1 Answer

1

I too had the same error.

I noticed that it occurs when multiple INSERT / SELECT statements were fired one after another.

I fixed it by adding @synchronized block around the sqlite code.

@synchronized (self){
  // sqlite code
}
answered on Stack Overflow May 29, 2013 by Akshay Shah • edited Jul 11, 2013 by tipycalFlow

User contributions licensed under CC BY-SA 3.0