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.
精彩评论