Skip to content

Commit

Permalink
make sure sqlite statement is finalized and database closed
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Mar 17, 2019
1 parent ce7c639 commit 9814fd5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ViberContactPhotoProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ - (DDNotificationContactPhotoPromiseOffer *)contactPhotoPromiseOfferForNotificat
NSString *iconsPath = [NSString stringWithFormat:@"%@/com.viber/ViberIcons", containerPath];

NSString *senderMemberId = [notification.applicationUserInfo valueForKey:@"senderMemberId"];
NSString *imageName;

const char *dbpath = [databasePath UTF8String];
sqlite3 *_viberdb;
Expand All @@ -20,17 +21,20 @@ - (DDNotificationContactPhotoPromiseOffer *)contactPhotoPromiseOfferForNotificat
if (sqlite3_prepare_v2(_viberdb, stmt, -1, &statement, NULL) == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_ROW) {
const unsigned char *result = sqlite3_column_text(statement, 0);
NSString *imageName = [NSString stringWithUTF8String:(char *)result];
NSString *imageURL = [NSString stringWithFormat:@"%@/%@.jpg", iconsPath, imageName];
UIImage *image = [UIImage imageWithContentsOfFile:imageURL];

return [NSClassFromString(@"DDNotificationContactPhotoPromiseOffer") offerInstantlyResolvingPromiseWithPhotoIdentifier:imageURL image:image];
imageName = [NSString stringWithUTF8String:(char *)result];
}
sqlite3_finalize(statement);
}
sqlite3_close(_viberdb);
}

return nil;
if (imageName) {
NSString *imageURL = [NSString stringWithFormat:@"%@/%@.jpg", iconsPath, imageName];
UIImage *image = [UIImage imageWithContentsOfFile:imageURL];

return [NSClassFromString(@"DDNotificationContactPhotoPromiseOffer") offerInstantlyResolvingPromiseWithPhotoIdentifier:imageURL image:image];
} else {
return nil;
}
}
@end

0 comments on commit 9814fd5

Please sign in to comment.