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” statement? 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: