Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) makeSitesSelect:(NSString *)dbPath:(NSString *)theSelect {
- allSitesSelect = [[NSMutableArray alloc] init];
- sqlite3 *database;
- if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
- const char *sql = [theSelect cStringUsingEncoding:NSASCIIStringEncoding];
- sqlite3_stmt *selectstmt;
- if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
- while(sqlite3_step(selectstmt) == SQLITE_ROW) {
- NSMutableArray *selResult = [[NSMutableArray alloc] init]; // <---- Memory leak
- NSInteger selprimaryKey = sqlite3_column_int(selectstmt, 0);
- [selResult addObject:[NSString stringWithFormat:@"%i", selprimaryKey]]; //<--- memory leak
- const unsigned char *chsiteSite = sqlite3_column_text(selectstmt, 1);
- const unsigned char *chsiteCity = sqlite3_column_text(selectstmt, 2);
- const unsigned char *chsiteCountry = sqlite3_column_text(selectstmt, 3);
- const unsigned char *chsiteGPS = sqlite3_column_text(selectstmt, 4);
- if (chsiteSite != NULL) {
- [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]]; //<--- memory leak
- }
- else {
- [selResult addObject:@""];
- }
- if (chsiteCity != NULL) {
- [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)]]; //<---- memory leak
- }
- else {
- [selResult addObject:@""];
- }
- if (chsiteCountry != NULL) {
- [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)]]; //<---- memory leak
- }
- else {
- [selResult addObject:@""];
- }
- if (chsiteGPS != NULL) {
- [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)]]; //<---- memory leak
- }
- else {
- [selResult addObject:@""];
- }
- [allSitesSelect addObject:selResult];
- [selResult release];
- }
- sqlite3_finalize(selectstmt);
- }
- sqlite3_close(database);
- }
- else
- sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
- }
- if (!allSitesSelect)
- {
- allSitesSelect = [[NSMutableArray alloc] init];
- }
- [allSitesSelect release];
- NSMutuableArray selResult*
- while(sqlite3_step(selectstmt) == SQLITE_ROW) {
- if(selResult == nil){
- selResult = [NSMutuableArray copy] //Its an autorelease(you don't need
- //release explicitly )
- }
- }
Add Comment
Please, Sign In to add comment