There's a memory leak in my program and because I'm not well versed in C (created a function in my Objective-C class to load strings from a SQLite database). Can anyone spot my blunder? Thank you:
static int MyCallback(void *context, int lCount, char **values, char **columns){
NSMutableArray *sqlRawStrings = (NSMutableArray *)context;
for (int i = 0; i < lCount; i++) {
const char *nameCString = values[i];
if (nameCString != NULL) {
[sqlRawStrings addObject:[NSString stringWithUTF8String:nameCString]];
}
}
return SQLITE_OK;
}
All this is called earlier here:
int numberA = [loadBundleNumber intValue];
char str1[130] = "select ";
for(int i = 7; i <7 + numberA; i++){
str1[i] = 'a';
}
char str2[20] = " from puzzles";
strcat(str1,str2);
NSString *file = [[NSBundle mainBundle] pathForResource:@"finalPuzzles" ofType:@"db"];
sqlite3 *database = NULL;
if (sqlite3_open([file UTF8String],&database) == SQLITE_OK) {
sqlite3_exec(database, str1, MyCallback, sqlRawStrings, NULL);
}
sqlite3_close(database);
Thanks