Question

I'm pulling and pushing data from an sqlite database. I use the FMDatabase cocoa wrapper.

I'm pulling and pushing data from multiple threads, but I made sure that more then one transactions never happen at the same time.

I get EXC_BAD_ACCESS after a few hundred call at the database but never at the same time. It's also not memory related (I've tried NSZombies and looked at the memory management of parameters).

Here is the stack and the code :

alt text http://grab.by/1VwY

FMResultSet* result = [db executeQuery:@"select latitude, longitude from cache where name = ?", name];
[result next];

NSString* latitude = [result stringForColumn:@"latitude"];
NSString* longitude = [result stringForColumn:@"longitude"];

I've got no idea, does somebody has one?

Was it helpful?

Solution

Looking through the relevant code in FMDatabase, it seems the sqlite_bind_text() routines uses the SQLITE_STATIC parameter to bind the result NSString's -UTF8String method (which returns an autoreleased pointer).

This means SQLite assumes that the text storage will remain valid for as long as the text remains bound, while the -UTF8String return is only valid for the current autorelease context. If you're using the same FMResultSet over multiple threads or function calls, changing that parameter to SQLITE_TRANSIENT would be much safer.

I'd suggest making that change in every sqlite3_bind_text() call and seeing if it still crashes. If that fixes it, you may want to report it back to the developer as a possible improvement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top