Guest User

Untitled

a guest
Jul 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. - (void) makeSitesSelect:(NSString *)dbPath:(NSString *)theSelect {
  2. allSitesSelect = [[NSMutableArray alloc] init];
  3. sqlite3 *database;
  4. if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
  5. const char *sql = [theSelect cStringUsingEncoding:NSASCIIStringEncoding];
  6. sqlite3_stmt *selectstmt;
  7.  
  8. if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
  9. while(sqlite3_step(selectstmt) == SQLITE_ROW) {
  10. NSMutableArray *selResult = [[NSMutableArray alloc] init]; // <---- Memory leak
  11. NSInteger selprimaryKey = sqlite3_column_int(selectstmt, 0);
  12. [selResult addObject:[NSString stringWithFormat:@"%i", selprimaryKey]]; //<--- memory leak
  13.  
  14. const unsigned char *chsiteSite = sqlite3_column_text(selectstmt, 1);
  15. const unsigned char *chsiteCity = sqlite3_column_text(selectstmt, 2);
  16. const unsigned char *chsiteCountry = sqlite3_column_text(selectstmt, 3);
  17. const unsigned char *chsiteGPS = sqlite3_column_text(selectstmt, 4);
  18.  
  19. if (chsiteSite != NULL) {
  20. [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]]; //<--- memory leak
  21. }
  22. else {
  23. [selResult addObject:@""];
  24. }
  25.  
  26. if (chsiteCity != NULL) {
  27. [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)]]; //<---- memory leak
  28. }
  29. else {
  30. [selResult addObject:@""];
  31. }
  32. if (chsiteCountry != NULL) {
  33. [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)]]; //<---- memory leak
  34. }
  35. else {
  36. [selResult addObject:@""];
  37. }
  38. if (chsiteGPS != NULL) {
  39. [selResult addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)]]; //<---- memory leak
  40. }
  41. else {
  42. [selResult addObject:@""];
  43. }
  44. [allSitesSelect addObject:selResult];
  45. [selResult release];
  46. }
  47. sqlite3_finalize(selectstmt);
  48. }
  49. sqlite3_close(database);
  50. }
  51. else
  52. sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
  53. }
  54.  
  55. if (!allSitesSelect)
  56. {
  57. allSitesSelect = [[NSMutableArray alloc] init];
  58. }
  59.  
  60. [allSitesSelect release];
  61.  
  62. NSMutuableArray selResult*
  63. while(sqlite3_step(selectstmt) == SQLITE_ROW) {
  64. if(selResult == nil){
  65. selResult = [NSMutuableArray copy] //Its an autorelease(you don't need
  66. //release explicitly )
  67. }
  68. }
Add Comment
Please, Sign In to add comment