开发者

EXC_BAD_ACCESS in SQLite on Mac OS

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 i开发者_JAVA技巧dea, does somebody has one?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜