开发者

sqlite3_exec is there a memory leak?

I'm using SQLite to store my data. I'm writing wrapper class, and I want to know: will be a memory leak if (res != SQLITE_OK) and errorMsg will be displayed to the screen??

So do I need to do free(errorMsg); in the "if" s开发者_C百科tatement? Thanx!

-(int) executeQuery: (NSString *) sqlQueryStr
{
char *errorMsg = NULL;
int res = SQLITE_ERROR;

res = sqlite3_exec(database, [sqlQueryStr UTF8String], NULL, NULL, &errorMsg);

if (res != SQLITE_OK)
{
    sqlite3_close(database); 
    NSLog(@"executeQuery Error:  %@", errorMsg);
    database = NULL;
    return res;
}

return res;
}


You should use sqlite3_free() to release the error message string, as per the documentation:

To avoid memory leaks, the application should invoke sqlite3_free() on error message strings returned through the 5th parameter of of sqlite3_exec() after the error message string is no longer needed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜