702 RHeap& myHeap = User::Heap(); |
702 RHeap& myHeap = User::Heap(); |
703 TInt firstSize = myHeap.Size(); |
703 TInt firstSize = myHeap.Size(); |
704 TInt biggestBlock; |
704 TInt biggestBlock; |
705 TInt firstAvail = myHeap.Available(biggestBlock); |
705 TInt firstAvail = myHeap.Available(biggestBlock); |
706 |
706 |
707 aRepository = CSharedRepository::NewL(aUid); |
707 TRAPD(err, aRepository = CSharedRepository::NewL(aUid)); |
708 #ifdef CACHE_OOM_TESTABILITY |
708 #ifdef CACHE_OOM_TESTABILITY |
709 if ((aRepository==NULL)&&!iTrapOOMOnOpen) |
709 if ((err!=KErrNone)&&!iTrapOOMOnOpen) |
710 { |
710 { |
711 User::Leave(KErrNoMemory); |
711 User::Leave(err); |
712 } |
712 } |
713 #endif |
713 #endif |
714 if ((aRepository==NULL)&&TServerResources::iCacheManager->Enabled()) |
714 if ((err!=KErrNone)&&TServerResources::iCacheManager->Enabled()) |
715 { |
715 { |
716 // If cache enabled, try recovery by releasing the cache |
716 // If cache enabled, try recovery by releasing the cache |
717 TServerResources::iCacheManager->FlushCache(EFalse); |
717 TServerResources::iCacheManager->FlushCache(EFalse); |
718 // retry |
718 // retry |
719 aRepository = CSharedRepository::NewL(aUid); |
719 aRepository = CSharedRepository::NewL(aUid); |
720 } |
720 err = KErrNone; |
721 // If still no memory, return error |
721 } |
722 if (aRepository==NULL) |
722 User::LeaveIfError(err); |
723 { |
723 CleanupStack::PushL(aRepository); |
724 User::Leave(KErrNoMemory); |
|
725 } |
|
726 else // successfully created the object, so push it into the cleanup stack |
|
727 { |
|
728 CleanupStack::PushL(aRepository); |
|
729 } |
|
730 |
724 |
731 // Now that we have enough memory for the object and constructed it properly |
725 // Now that we have enough memory for the object and constructed it properly |
732 // we try to load it. We trap all errors, either from leaving functions or error code |
726 // we try to load it. We trap all errors, either from leaving functions or error code |
733 // returning functions and unify them (in all cases only one of these codes will |
727 // returning functions and unify them (in all cases only one of these codes will |
734 // contain a valid value and the other will be 0, and for our purposes we treat |
728 // contain a valid value and the other will be 0, and for our purposes we treat |