views:

295

answers:

1

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

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?

+2  A: 

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.

Boaz Stuller
That makes sense. Thanks, testing that out!
gcamp
Didn't make any change… :/ Still crashing the same way.
gcamp
Oh well. I suspect we'll need to see more of the code to figure out what was wrong. One thing you can do to help is to download the sqlite amalgamation and compile your project with that. That way you'll have full debugging symbols, and you can turn on the SQLITE_DEBUG preprocessor macro.
Boaz Stuller
Cleaned and rebuild the project and it works! Thanks! Will report that to Gus too!
gcamp