userlibandfileserver/domainmgr/src/domaincli.cpp
branchRCL_3
changeset 42 a179b74831c9
parent 0 a41df078684a
--- a/userlibandfileserver/domainmgr/src/domaincli.cpp	Thu Jul 15 20:11:42 2010 +0300
+++ b/userlibandfileserver/domainmgr/src/domaincli.cpp	Thu Aug 19 11:14:22 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -19,6 +19,7 @@
 #include <e32base_private.h>
 #include <e32property.h>
 
+
 #include <domainmember.h>
 #include <domainmanager.h>
 #include "domainobserver.h"
@@ -380,26 +381,43 @@
 	{
 	__DM_ASSERT(Handle() != KNullHandle);
 
+	
 	aTransitionFailures.Reset();
 
 	TInt err = KErrNone;
-
+		
 	TInt failureCount = GetTransitionFailureCount();
 	if (failureCount <= 0)
 		return failureCount;
-
+	
+	// Pre-allocate array with a known size which for this case is the value in failureCount 
+	// in order to guarantee that future append operations to the array aTransitionFailures would
+	// not fail. This is assuming that the pre-allocated size is not exceeded.
+	err=aTransitionFailures.Reserve(failureCount); 
+	if (err != KErrNone)
+		return err;
+		
 	TTransitionFailure* failures = new TTransitionFailure[failureCount];
 	if(failures == NULL)
+		{		
+		aTransitionFailures.Reset();
 		return(KErrNoMemory);
+		}
+	
 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure));
 
 	TIpcArgs a(&dataPtr);
 	err = RSessionBase::SendReceive(EDmGetTransitionFailures, a);
-	
+
 	if (err == KErrNone)
 		{
-		for (TInt i=0; i<failureCount; i++)
-			aTransitionFailures.Append(failures[i]);
+		for (TInt i=0; i<failureCount; i++)	
+			{
+			err = aTransitionFailures.Append(failures[i]);		
+			//The pre-allocation made above for the array aTransitionFailures should guarantee
+			//that append operations complete succesfully.			
+			__DM_ASSERT(err == KErrNone);	
+			}
 		}
 
 	delete [] failures;
@@ -439,19 +457,34 @@
 	if (count <= 0)
 		return KErrGeneral;
 
+	// Pre-allocate array with a known size which for this case is the value in count 
+	// in order to guarantee that future append operations to the array aTransitionFailures 
+	// would not fail. This is assuming that the pre-allocated size is not exceeded.
+	TInt ret=aTransitions.Reserve(count); 
+	if (ret != KErrNone)
+		return ret;
+
 	TTransInfo* trans = new TTransInfo[count];
 	if(trans == NULL)
+		{
+		aTransitions.Reset();
 		return(KErrNoMemory);
+		}
 	
 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo));
 
 	TIpcArgs a(&dataPtr);
-	TInt ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
+	ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
 	
 	if(ret==KErrNone)
 		{
 		for (TInt i=0; i<count; i++)
-			aTransitions.Append(trans[i]);
+			{
+			ret = aTransitions.Append(trans[i]);					
+			//The pre-allocation made above for the array aTransitions should guarantee
+			//that append operations complete succesfully.
+			__DM_ASSERT(ret == KErrNone);					
+			}
 		}
 	
 	delete [] trans;