commit ed7a8f0a0c31c20d35e567e1625c0edfe77b8276
Author: Genli Pan <genli.pan@windriver.com>
Date:   Mon Jul 6 18:03:15 2015 +0800

fix logical errors in transport delegate testcases

There are obvious logical errors and redundant code in these testcases.
Resouces are not been released properly. they didn't cause errors in some
TPM chips because these TPMs have enough resouces to be abused.
But in Atmel TPM resource is so limited that allows no abusing.

Signed-off-by: Genli Pan <genli.pan@windriver.com>

diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
index fd59e47..12ebd69 100644
--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
@@ -86,8 +86,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("connect_load_all", result);
-		Tspi_Context_FreeMemory( hContext, NULL );
-		Tspi_Context_Close( hContext );
 		exit( result );
 	}
 
@@ -99,33 +97,20 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
+	} else {
 
+	/* Invalidate the family to avoid resource exhaustion */
+	if (hFamily != NULL_HDELFAMILY)
+		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("Testsuite_Transport_Final", result);
-		goto done;
 	}
 	else
 	{
@@ -133,11 +118,6 @@ main_v1_2( char version )
 	}
 
 	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
index 3dd3299..3fe8cff 100644
--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
@@ -86,8 +86,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("connect_load_all", result);
-		Tspi_Context_FreeMemory( hContext, NULL );
-		Tspi_Context_Close( hContext );
 		exit( result );
 	}
 
@@ -99,33 +97,20 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
+	} else {
 
+	/* Invalidate the family to avoid resource exhaustion */
+	if (hFamily != NULL_HDELFAMILY)
+		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("Testsuite_Transport_Final", result);
-		goto done;
 	}
 	else
 	{
@@ -133,11 +118,6 @@ main_v1_2( char version )
 	}
 
 	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
index 8b149d2..98c6127 100644
--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
@@ -86,8 +86,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("connect_load_all", result);
-		Tspi_Context_FreeMemory( hContext, NULL );
-		Tspi_Context_Close( hContext );
 		exit( result );
 	}
 
@@ -99,33 +97,20 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
+	} else {
 
+	/* Invalidate the family to avoid resource exhaustion */
+	if (hFamily != NULL_HDELFAMILY)
+		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
 	result = Testsuite_Transport_Final(hContext, 0);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("Testsuite_Transport_Final", result);
-		goto done;
 	}
 	else
 	{
@@ -133,11 +118,6 @@ main_v1_2( char version )
 	}
 
 	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
index 663c6eb..ef9cac1 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
@@ -89,7 +89,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error("connect_load_all", result);
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -100,21 +100,20 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", result );
+		goto done_trans;
 	}
 
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
+			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
+		print_error( "Tspi_SetAttribUint32", result );
 		goto done;
 	}
-
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
@@ -154,21 +153,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
-
-	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
-			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_SetAttribUint32", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
@@ -182,27 +166,22 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", result );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
 	Tspi_Context_Close( hContext );
-
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
index eaed650..d3c19e8 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
@@ -88,8 +88,8 @@ main_v1_2( char version )
 	result = connect_load_all(&hContext, &hSRK, &hTPM);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "connect_load_all", result );
-		goto done;
+		print_error( "connect_load_all", result);
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -100,21 +100,20 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", result );
+		goto done_trans;
 	}
 
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
+			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
+		print_error( "Tspi_SetAttribUint32", result );
 		goto done;
 	}
-
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
@@ -154,21 +153,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
-
-	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
-			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_SetAttribUint32", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
@@ -182,27 +166,22 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", result );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
 	Tspi_Context_Close( hContext );
-
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
index 0585386..b84fd55 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
@@ -89,7 +89,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", result );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -100,18 +100,18 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", result );
+		goto done_trans;
 	}
 
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
+			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
+		print_error( "Tspi_SetAttribUint32", result );
 		goto done;
 	}
 
@@ -154,21 +154,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", result );
-		goto done;
-	}
-
-	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
-			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_SetAttribUint32", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
@@ -182,27 +167,23 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", result );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
-	Tspi_Context_Close( hContext );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, 0);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
 
+	Tspi_Context_Close( hContext );
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
index 66708e2..51a59c2 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
@@ -89,7 +89,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -99,19 +99,12 @@ main_v1_2( char version )
 		Tspi_Context_Close(hContext);
 		exit(result);
 	}
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
 
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
@@ -160,38 +153,27 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
+
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
index 42b5709..8263422 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
@@ -89,7 +89,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -100,19 +100,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
@@ -161,38 +153,27 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
+
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
index bdfa2f2..1a139e0 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
@@ -75,7 +75,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_CreateKeyDelegation-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HKEY		hKey;
@@ -89,7 +89,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -100,19 +100,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
@@ -161,38 +153,27 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", result);
+	}
+
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
index e8e225e..e714e13 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -98,20 +98,6 @@ main_v1_2( char version )
 		Tspi_Context_Close(hContext);
 		exit(result);
 	}
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
 	if ( result != TSS_SUCCESS )
@@ -163,26 +149,22 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
+	}
+	else
+	{
+		print_success( function, result );
 	}
 
+	/* Invalidate the family to avoid resource exhaustion */
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done:
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( function, (result) );
-		goto done;
-	}
-	else
-	{
-		print_success( function, result );
+		print_error( "Testsuite_Transport_Final", (result) );
 	}
 
 	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
 
 	exit( result );
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
index d372cb5..66a75ec 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -98,20 +98,6 @@ main_v1_2( char version )
 		Tspi_Context_Close(hContext);
 		exit(result);
 	}
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
 	if ( result != TSS_SUCCESS )
@@ -163,26 +149,22 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
+	}
+	else
+	{
+		print_success( function, result );
 	}
 
+	/* Invalidate the family to avoid resource exhaustion */
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done:
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( function, (result) );
-		goto done;
-	}
-	else
-	{
-		print_success( function, result );
+		print_error( "Testsuite_Transport_Final", (result) );
 	}
 
 	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
 
 	exit( result );
diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
index 18246de..89eca65 100644
--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
@@ -75,7 +75,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_CreateOwnerDelegation-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HPOLICY		hDelegation = NULL_HPOLICY;
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -98,20 +98,6 @@ main_v1_2( char version )
 		Tspi_Context_Close(hContext);
 		exit(result);
 	}
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
 	if ( result != TSS_SUCCESS )
@@ -163,26 +149,22 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
 
-	print_end_test( function );
-done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done:
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
+
+	print_end_test( function );
 	Tspi_Context_Close( hContext );
 
 	exit( result );
diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
index f5a376d..8c190a6 100644
--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -99,27 +99,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
+	} else {
 
 	result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
 			TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
@@ -151,7 +135,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		if( !(checkNonAPI(result)) )
@@ -178,13 +161,13 @@ main_v1_2( char version )
 		}
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	Tspi_Context_Close( hContext );
 
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
index 2249727..ddd1af0 100644
--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -99,27 +99,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
+	} else {
 
 	result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
 			TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
@@ -151,7 +135,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		if( !(checkNonAPI(result)) )
@@ -178,13 +161,13 @@ main_v1_2( char version )
 		}
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	Tspi_Context_Close( hContext );
 
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
index d45c5f2..aa07e69 100644
--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
@@ -88,7 +88,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -99,27 +99,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
+	} else {
 
 	result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
 			TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
@@ -147,13 +131,6 @@ main_v1_2( char version )
 			TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &returnedID);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_GetAttribUint32", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
 		if( !(checkNonAPI(result)) )
 		{
 			print_error( "Tspi_TPM_GetAttribUint32", result );
@@ -162,7 +139,6 @@ main_v1_2( char version )
 		{
 			print_error_nonapi( "Tspi_TPM_GetAttribUint32", result );
 		}
-		goto done;
 	}
 	else
 	{
@@ -170,7 +146,6 @@ main_v1_2( char version )
 		{
 			print_error( "Tspi_GetAttribUint32: Family IDs do not match", TSS_E_FAIL );
 			result = 1;
-			goto done;
 		}
 		else
 		{
@@ -178,13 +153,13 @@ main_v1_2( char version )
 		}
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+	}
+	result = Testsuite_Transport_Final(hContext, 0);
 	Tspi_Context_Close( hContext );
 
+	print_end_test( function );
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
index e9ccac7..7406c3d 100644
--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
@@ -87,7 +87,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -98,21 +98,6 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
@@ -124,26 +109,20 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
-		goto done;
 	}
-
+	else
+	{
+		print_success( function, result );
+	}
+done:
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
-	}
-	else
-	{
-		print_success( function, result );
 	}
 
-	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
index 146c735..af5fd66 100644
--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
@@ -87,7 +87,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -98,21 +98,6 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
@@ -124,26 +109,20 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
-		goto done;
 	}
-
+	else
+	{
+		print_success( function, result );
+	}
+done:
 	result = Testsuite_Transport_Final(hContext, hSigningKey);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
-	}
-	else
-	{
-		print_success( function, result );
 	}
 
-	print_end_test( function );
-done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
index 510c197..b09a717 100644
--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
@@ -75,7 +75,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_InvalidateFamily-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HDELFAMILY		hFamily = NULL_HDELFAMILY;
@@ -87,7 +87,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -98,21 +98,6 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
@@ -124,26 +109,20 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
-	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
+
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
index 594beba..a64445e 100644
--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
@@ -90,7 +90,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		Tspi_Context_FreeMemory( hContext, NULL );
 		Tspi_Context_Close( hContext );
 		exit( result );
 	}
@@ -103,26 +102,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
+		goto done_trans;
 	}
 
 	result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
@@ -132,40 +116,32 @@ main_v1_2( char version )
 		print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
 		goto done;
 	}
+	else
+	{
+		print_success( function, result );
+	}
 
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
+	if (result != TSS_SUCCESS)
 	{
-		print_error( function, (result) );
-		goto done;
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-	else
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
+	if (result != TSS_SUCCESS)
 	{
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-		else
-		{
-			print_success( function, result );
-		}
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( function, (result) );
+	}
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
index 25b6010..7a72693 100644
--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
@@ -90,7 +90,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		Tspi_Context_FreeMemory( hContext, NULL );
 		Tspi_Context_Close( hContext );
 		exit( result );
 	}
@@ -103,26 +102,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
+		goto done_trans;
 	}
 
 	result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
@@ -132,40 +116,32 @@ main_v1_2( char version )
 		print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
 		goto done;
 	}
+	else
+	{
+		print_success( function, result );
+	}
 
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
+	if (result != TSS_SUCCESS)
 	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-	else
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
+	if (result != TSS_SUCCESS)
 	{
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-		else
-		{
-			print_success( function, result );
-		}
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( function, (result) );
+	}
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
index 4d3c355..678617b 100644
--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
@@ -75,7 +75,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_ReadTables-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HDELFAMILY		hFamily = NULL_HDELFAMILY;
@@ -90,7 +90,6 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		Tspi_Context_FreeMemory( hContext, NULL );
 		Tspi_Context_Close( hContext );
 		exit( result );
 	}
@@ -103,26 +102,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
+		goto done_trans;
 	}
 
 	result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
@@ -132,40 +116,32 @@ main_v1_2( char version )
 		print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
 		goto done;
 	}
+	else
+	{
+		print_success( function, result );
+	}
 
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
+	if (result != TSS_SUCCESS)
 	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-	else
+	result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
+	if (result != TSS_SUCCESS)
 	{
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-
-		result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
-		if (result != TSS_SUCCESS)
-		{
-			print_error( "Tspi_Context_FreeMemory", result );
-			goto done;
-		}
-		else
-		{
-			print_success( function, result );
-		}
+		print_error( "Tspi_Context_FreeMemory", result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
-	if (hFamily != NULL_HDELFAMILY)
-		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+	Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
+done_trans:
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( function, (result) );
+	}
 	Tspi_Context_Close( hContext );
-	exit( 0 );
+	print_end_test( function );
+
+	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
index 4bb015c..b3e1339 100644
--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
 	if ( result != TSS_SUCCESS )
 	{
@@ -222,27 +207,24 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
index 5e9db88..119d023 100644
--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
 	if ( result != TSS_SUCCESS )
 	{
@@ -222,27 +207,24 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
index 140c896..87e9f9f 100644
--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
@@ -78,7 +78,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_UpdateVerificationCount-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HPOLICY		hDelegation1 = NULL_HPOLICY;
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
 	if ( result != TSS_SUCCESS )
 	{
@@ -222,27 +207,24 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
 
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
index cd18449..c3789dd 100644
--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
 			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
@@ -238,27 +223,23 @@ main_v1_2( char version )
 	if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
 	{
 		print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result == TSS_SUCCESS )
-	{
-		print_error( "Testsuite_Transport_Final", (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
index 50aa5d7..ad2cae7 100644
--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
 			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
@@ -183,7 +168,7 @@ main_v1_2( char version )
 	result = Tspi_TPM_Delegate_VerifyDelegation(hDelegation1);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
+		print_error( function, (result) );
 		goto done;
 	}
 
@@ -238,27 +223,23 @@ main_v1_2( char version )
 	if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
 	{
 		print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, hSigningKey);
-	if ( result == TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, hSigningKey);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
index 33159a2..2cdabef 100644
--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
@@ -78,7 +78,7 @@ main_v1_2( char version )
 {
 	char *			function = "Tspi_TPM_Delegate_VerifyDelegation-trans03";
 	TSS_HCONTEXT		hContext;
-	TSS_HKEY		hSRK, hWrappingKey;
+	TSS_HKEY		hSRK, hSigningKey, hWrappingKey;
 	TSS_HTPM		hTPM;
 	TSS_HPOLICY		hTPMPolicy;
 	TSS_HPOLICY		hDelegation1 = NULL_HPOLICY;
@@ -92,7 +92,7 @@ main_v1_2( char version )
 	if ( result != TSS_SUCCESS )
 	{
 		print_error( "connect_load_all", (result) );
-		goto done;
+		exit(result);
 	}
 
 	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
@@ -103,19 +103,11 @@ main_v1_2( char version )
 		exit(result);
 	}
 
-	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_GetPolicyObject", result );
-		goto done;
-	}
-
-	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
-					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
+	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_Policy_SetSecret", result );
-		goto done;
+		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
+		goto done_trans;
 	}
 
 	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
@@ -157,13 +149,6 @@ main_v1_2( char version )
 		goto done;
 	}
 
-	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
-	if ( result != TSS_SUCCESS )
-	{
-		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
-		goto done;
-	}
-
 	result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
 			TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
 	if ( result != TSS_SUCCESS )
@@ -183,7 +168,7 @@ main_v1_2( char version )
 	result = Tspi_TPM_Delegate_VerifyDelegation(hDelegation1);
 	if ( result != TSS_SUCCESS )
 	{
-		print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
+		print_error( function, (result) );
 		goto done;
 	}
 
@@ -238,27 +223,23 @@ main_v1_2( char version )
 	if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
 	{
 		print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
-		goto done;
-	}
-
-	result = Testsuite_Transport_Final(hContext, 0);
-	if ( result == TSS_SUCCESS )
-	{
-		print_error( function, (result) );
-		goto done;
 	}
 	else
 	{
 		print_success( function, result );
 	}
-
-	print_end_test( function );
 done:
 	/* Invalidate the family to avoid resource exhaustion */
 	if (hFamily != NULL_HDELFAMILY)
 		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
-	Tspi_Context_FreeMemory( hContext, NULL );
+done_trans:
+	result = Testsuite_Transport_Final(hContext, NULL);
+	if ( result != TSS_SUCCESS )
+	{
+		print_error( "Testsuite_Transport_Final", (result) );
+	}
 	Tspi_Context_Close( hContext );
+	print_end_test( function );
 
 	exit( result );
 }
