improved error handling
authorJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 5 Jun 2006 17:49:34 +0000 (17:49 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 5 Jun 2006 17:49:34 +0000 (17:49 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/ccapi@18083 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/ccapi/client/cacheapi.c
src/lib/ccapi/client/ccache.c
src/lib/ccapi/client/ccache_iterator.c
src/lib/ccapi/client/context.c
src/lib/ccapi/client/credentials_iterator.c
src/lib/ccapi/common/msg.c
src/lib/ccapi/unit-test/NTMakefile
src/lib/ccapi/windows/client.c
src/lib/ccapi/windows/server.c

index 14a1eb476218ccdb8204b6f180fe8b683dc3166d..c76ebe457074f61377b643acd73dac8b5ddb2783 100644 (file)
@@ -64,9 +64,9 @@ cc_initialize (       cc_context_t*           outContext,
                 char const**           outVendor)
 {
     static char vendor[128] = "";
-    cc_msg_t     *request;
+    cc_msg_t     *request = NULL;
     ccmsg_init_t *request_header;
-    cc_msg_t     *response;
+    cc_msg_t     *response = NULL;
     cc_uint32 type;
     ccmsg_init_resp_t *response_header;
     cc_int32 code;
@@ -100,14 +100,17 @@ cc_initialize (   cc_context_t*           outContext,
     request_header->in_version = htonl(inVersion);
 
     code = cci_msg_new(ccmsg_INIT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+               goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_init_t));
+       if (code != ccNoError) 
+               goto cleanup;
+       request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+       if (code != ccNoError)
+               goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -131,8 +134,15 @@ cc_initialize (    cc_context_t*           outContext,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
index 790ff6f671f5fbc11920197d52333e3a62940787..e4b9673c7b1833dab8b83dc2402beed1530c66c0 100644 (file)
@@ -107,9 +107,9 @@ cc_int32
 cc_int_ccache_release( cc_ccache_t ccache )
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_release_t     *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_release_t     *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -128,14 +128,17 @@ cc_int_ccache_release( cc_ccache_t ccache )
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_RELEASE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+        goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_release_t));
+    if (code != ccNoError)
+        goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+        goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -146,9 +149,16 @@ cc_int_ccache_release( cc_ccache_t ccache )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
-    free(int_ccache->functions);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
+    if (int_ccache->functions)
+       free(int_ccache->functions);
     free(int_ccache);
     return code;
 }
@@ -158,9 +168,9 @@ cc_int32
 cc_int_ccache_destroy( cc_ccache_t ccache )
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_destroy_t     *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_destroy_t     *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -179,14 +189,17 @@ cc_int_ccache_destroy( cc_ccache_t ccache )
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_DESTROY, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_destroy_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -197,8 +210,14 @@ cc_int_ccache_destroy( cc_ccache_t ccache )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     free(ccache);
     return code;
 }
@@ -208,9 +227,9 @@ cc_int32
 cc_int_ccache_set_default( cc_ccache_t ccache )
 {
     cc_int_ccache_t                    int_ccache;
-    cc_msg_t                           *request;
-    ccmsg_ccache_set_default_t                 *request_header;
-    cc_msg_t                           *response;
+    cc_msg_t                           *request = NULL;
+    ccmsg_ccache_set_default_t                 *request_header = NULL;
+    cc_msg_t                           *response = NULL;
     cc_uint32                          type;
     cc_int32                           code;
 
@@ -229,14 +248,17 @@ cc_int_ccache_set_default( cc_ccache_t ccache )
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_SET_DEFAULT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_default_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -247,8 +269,14 @@ cc_int_ccache_set_default( cc_ccache_t ccache )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -257,9 +285,9 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
                                    cc_uint32* credentials_version)
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_get_creds_version_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_get_creds_version_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -278,14 +306,17 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_CREDS_VERSION, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_creds_version_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -298,8 +329,14 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -307,9 +344,9 @@ cc_int32
 cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_get_name_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_get_name_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -328,14 +365,17 @@ cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name )
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_NAME, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_name_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -353,8 +393,14 @@ cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -364,9 +410,9 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
                         cc_string_t* principal )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_get_principal_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_get_principal_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -386,14 +432,17 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
     request_header->version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_principal_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -411,8 +460,14 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -423,9 +478,9 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
 {
     cc_uint32          blob_pos;
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_set_principal_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_set_principal_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -445,24 +500,24 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
     request_header->version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_data_blob(request, (void*)principal, strlen(principal) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
     
     request_header->principal_offset = htonl(blob_pos);
     request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_principal_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -473,8 +528,14 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -483,9 +544,9 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
                                         cc_credentials_iterator_t* iterator )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_creds_iterator_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_creds_iterator_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -504,14 +565,17 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_NEW_CREDS_ITERATOR, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_creds_iterator_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -524,8 +588,14 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -534,9 +604,9 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
                              const cc_credentials_union* credentials )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_store_creds_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_store_creds_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     char               *flat_cred = 0;
     cc_uint32          flat_cred_len = 0;
     cc_uint32          blob_pos;
@@ -558,10 +628,8 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_STORE_CREDS, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     switch ( credentials->version ) {
     case cc_credentials_v4:
@@ -571,30 +639,27 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
         code = cci_creds_v5_marshall(credentials->credentials.credentials_v5, &flat_cred, &flat_cred_len);
         break;
     default:
-        cci_msg_destroy(request);
-        free(request_header);
-        return ccErrBadCredentialsVersion;
-    }
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
+        code = ccErrBadCredentialsVersion;
     }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_data_blob(request, (void*)flat_cred, flat_cred_len, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
     
     request_header->creds_version = htonl(credentials->version);
     request_header->creds_offset = htonl(blob_pos);
     request_header->creds_len = htonl(flat_cred_len);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_store_creds_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -605,9 +670,16 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    free(flat_cred);
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (flat_cred)
+       free(flat_cred);
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -617,9 +689,9 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache,
 {
     cc_int_ccache_t            int_ccache;
     cc_int_credentials_t       int_creds;
-    cc_msg_t                   *request;
-    ccmsg_ccache_rem_creds_t   *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_rem_creds_t   *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -644,14 +716,17 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache,
     request_header->creds  = htonll(int_creds->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_REM_CREDS, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_rem_creds_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -662,8 +737,14 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -674,9 +755,9 @@ cc_int_ccache_move( cc_ccache_t source,
 {
     cc_int_ccache_t    int_ccache_source;
     cc_int_ccache_t    int_ccache_dest;
-    cc_msg_t           *request;
-    ccmsg_ccache_move_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_move_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -698,18 +779,21 @@ cc_int_ccache_move( cc_ccache_t source,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CCACHE_MOVE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_ccache_source->ctx);
     request_header->ccache_source = htonll(int_ccache_source->handle);
     request_header->ccache_dest = htonll(int_ccache_dest->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_move_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -720,8 +804,14 @@ cc_int_ccache_move( cc_ccache_t source,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }       
 
@@ -730,9 +820,9 @@ cc_int_ccache_lock( cc_ccache_t ccache,
                 cc_uint32 block )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_lock_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_lock_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -752,18 +842,21 @@ cc_int_ccache_lock( cc_ccache_t ccache,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CCACHE_LOCK, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_ccache->ctx);
     request_header->ccache = htonll(int_ccache->handle);
     request_header->lock_type = htonl(lock_type);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_lock_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -776,8 +869,14 @@ cc_int_ccache_lock( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -785,9 +884,9 @@ cc_int32
 cc_int_ccache_unlock( cc_ccache_t ccache )
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_unlock_t      *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_unlock_t      *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -804,17 +903,20 @@ cc_int_ccache_unlock( cc_ccache_t ccache )
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CCACHE_UNLOCK, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_ccache->ctx);
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_unlock_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = htonl(response->type);
     if (type == ccmsg_NACK) {
@@ -825,8 +927,14 @@ cc_int_ccache_unlock( cc_ccache_t ccache )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -836,9 +944,9 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
                                      cc_time* time_offset )
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_get_last_default_time_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_get_last_default_time_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_time64                  t64;
     cc_int32                   code;
@@ -858,14 +966,17 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_LAST_DEFAULT_TIME, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_last_default_time_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -880,8 +991,14 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -889,9 +1006,9 @@ cc_int32
 cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_get_change_time_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_get_change_time_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_time64          t64;
     cc_uint32          type;
     cc_int32           code;
@@ -911,14 +1028,17 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time )
     request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_CHANGE_TIME, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_change_time_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -933,8 +1053,14 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -945,9 +1071,9 @@ cc_int_ccache_compare( cc_ccache_t ccache,
 {
     cc_int_ccache_t            int_ccache;
     cc_int_ccache_t            int_compare_to;
-    cc_msg_t                   *request;
-    ccmsg_ccache_compare_t     *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_compare_t     *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -969,14 +1095,17 @@ cc_int_ccache_compare( cc_ccache_t ccache,
     request_header->ccache2 = htonll(int_compare_to->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_COMPARE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_compare_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -989,8 +1118,14 @@ cc_int_ccache_compare( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -1000,9 +1135,9 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
                                cc_time*        time_offset )
 {
     cc_int_ccache_t            int_ccache;
-    cc_msg_t                   *request;
-    ccmsg_ccache_get_kdc_time_offset_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_get_kdc_time_offset_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -1022,14 +1157,17 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
     request_header->creds_version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_KDC_TIME_OFFSET, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_kdc_time_offset_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -1042,8 +1180,14 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -1053,9 +1197,9 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
                                cc_time time_offset )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_set_kdc_time_offset_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_set_kdc_time_offset_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_int64           t64;
     cc_uint32          type;
     cc_int32           code;
@@ -1078,14 +1222,17 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
     request_header->offset = htonll(t64);
 
     code = cci_msg_new(ccmsg_CCACHE_SET_KDC_TIME_OFFSET, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_kdc_time_offset_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -1096,8 +1243,14 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
                                 
@@ -1106,9 +1259,9 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t  ccache,
                                  cc_int32      credentials_version )
 {
     cc_int_ccache_t    int_ccache;
-    cc_msg_t           *request;
-    ccmsg_ccache_clear_kdc_time_offset_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_clear_kdc_time_offset_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -1128,14 +1281,17 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t        ccache,
     request_header->creds_version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_clear_kdc_time_offset_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -1146,7 +1302,13 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t ccache,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
index b0ccbe61010bbe66eb095870ee78ab06db3e7fdf..3da9b35478d04072c2178584de3686ba8befdab6 100644 (file)
@@ -58,7 +58,7 @@ cc_int_ccache_iterator_new( cc_ccache_iterator_t * piter,
                             cc_handle ctx,
                             cc_handle handle )
 {
-    cc_int_ccache_iterator_t iter;
+    cc_int_ccache_iterator_t iter = NULL;
 
     if ( piter == NULL )
         return ccErrBadParam;
@@ -68,7 +68,7 @@ cc_int_ccache_iterator_new( cc_ccache_iterator_t * piter,
         return ccErrNoMem;
 
     iter->functions = (cc_ccache_iterator_f*)malloc( sizeof(cc_ccache_iterator_f));
-    if ( iter->functions ) {
+    if ( iter->functions == NULL ) {
         free(iter);
         return ccErrNoMem;
     }
@@ -87,9 +87,9 @@ cc_int32
 cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
 {
     cc_int_ccache_iterator_t   int_iter;
-    cc_msg_t                   *request;
-    ccmsg_ccache_iterator_release_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_iterator_release_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -108,14 +108,17 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
     request_header->ctx = htonll(int_iter->ctx);
     request_header->iterator = htonll(int_iter->handle);
     code = cci_msg_new(ccmsg_CCACHE_ITERATOR_RELEASE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_release_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -126,11 +129,19 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
 
-    free(int_iter->functions);
-    free(int_iter);
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
+
+    if (int_iter->functions)
+       free(int_iter->functions);
+    if (iter)
+       free(int_iter);
     return ccNoError;
 }
 
@@ -139,9 +150,9 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
                              cc_ccache_t * ccache )
 {
     cc_int_ccache_iterator_t   int_iter;
-    cc_msg_t                   *request;
-    ccmsg_ccache_iterator_next_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_iterator_next_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -160,14 +171,17 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
     request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_ITERATOR_NEXT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_next_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -179,8 +193,14 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+    
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -189,9 +209,9 @@ cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter,
                               cc_ccache_iterator_t * new_iter )
 {
     cc_int_ccache_iterator_t   int_iter;
-    cc_msg_t                   *request;
-    ccmsg_ccache_iterator_clone_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ccache_iterator_clone_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -210,14 +230,17 @@ cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter,
     request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_ITERATOR_CLONE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_clone_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -229,7 +252,13 @@ cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
index 8515f695beccf7989e336eac335de39e9c865893..8a79fcedef8f50574b7924a4b2f758a2d76d6289 100644 (file)
@@ -97,9 +97,9 @@ cc_int32
 cc_int_context_release( cc_context_t context )
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ctx_release_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_release_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -117,14 +117,17 @@ cc_int_context_release( cc_context_t context )
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_RELEASE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_release_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -135,8 +138,14 @@ cc_int_context_release( cc_context_t context )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       request_header = NULL;
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     free(int_context->functions);
     free(int_context);
     return code;
@@ -147,9 +156,9 @@ cc_int_context_get_change_time( cc_context_t context,
                                 cc_time* time)
 {
     cc_int_context_t           int_context;
-    cc_msg_t                   *request;
-    ccmsg_ctx_get_change_time_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_ctx_get_change_time_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     ccmsg_ctx_get_change_time_resp_t *response_header;
     cc_time64          t64;
     cc_uint32                  type;
@@ -169,14 +178,17 @@ cc_int_context_get_change_time( cc_context_t context,
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_GET_CHANGE_TIME, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_get_change_time_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -191,8 +203,14 @@ cc_int_context_get_change_time( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -201,10 +219,11 @@ cc_int_context_get_default_ccache_name( cc_context_t context,
                                         cc_string_t* name )
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ctx_get_default_ccache_name_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_get_default_ccache_name_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ctx_get_default_ccache_name_resp_t *response_header;
+    char               *string = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -222,33 +241,41 @@ cc_int_context_get_default_ccache_name( cc_context_t context,
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_GET_DEFAULT_CCACHE_NAME, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_get_default_ccache_name_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
         code = ntohl(nack_header->err_code);
     } else if (type == ccmsg_ACK) {
-        char * string;
         response_header = (ccmsg_ctx_get_default_ccache_name_resp_t*)response->header;
         code = cci_msg_retrieve_blob(response, response_header->name_offset, 
                                      response_header->name_len, &string);
-        if (code == ccNoError) {
+        if (code == ccNoError)
             code = cci_string_new(name, string);
-            free(string);
-        }
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (string)
+       free(string);
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -258,9 +285,9 @@ cc_int_context_compare( cc_context_t context,
                         cc_uint32* equal )
 {
     cc_int_context_t int_context, int_compare_to;
-    cc_msg_t        *request;
-    ccmsg_ctx_compare_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_compare_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ctx_compare_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -283,14 +310,17 @@ cc_int_context_compare( cc_context_t context,
     request_header->ctx2 = htonll(int_compare_to->handle);
 
     code = cci_msg_new(ccmsg_CTX_COMPARE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_compare_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -303,8 +333,14 @@ cc_int_context_compare( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -314,9 +350,9 @@ cc_int_context_new_ccache_iterator( cc_context_t context,
                                     cc_ccache_iterator_t* iterator )
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ctx_new_ccache_iterator_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_new_ccache_iterator_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ctx_new_ccache_iterator_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -335,14 +371,17 @@ cc_int_context_new_ccache_iterator( cc_context_t context,
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_NEW_CCACHE_ITERATOR, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_new_ccache_iterator_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -355,8 +394,14 @@ cc_int_context_new_ccache_iterator( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -367,9 +412,9 @@ cc_int_context_open_ccache( cc_context_t context,
 {
     cc_uint32          blob_pos;
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ccache_open_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_open_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ccache_open_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -387,25 +432,25 @@ cc_int_context_open_ccache( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_data_blob(request, (void *)name, strlen(name) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
     
     request_header->ctx = htonll(int_context->handle);
     request_header->name_offset = htonl(blob_pos);
     request_header->name_len = htonl(strlen(name) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_open_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -417,8 +462,14 @@ cc_int_context_open_ccache( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -427,9 +478,9 @@ cc_int_context_open_default_ccache( cc_context_t context,
                                     cc_ccache_t* ccache)
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ccache_open_default_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_open_default_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ccache_open_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -447,16 +498,19 @@ cc_int_context_open_default_ccache( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN_DEFAULT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_open_default_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -468,8 +522,14 @@ cc_int_context_open_default_ccache( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+    
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -482,9 +542,9 @@ cc_int_context_create_ccache( cc_context_t context,
 {
     cc_uint32          blob_pos;
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ccache_create_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_create_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ccache_create_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -504,17 +564,12 @@ cc_int_context_create_ccache( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_data_blob(request, (void *)name, strlen(name) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
     
     request_header->ctx = htonll(int_context->handle);
     request_header->version = htonl(cred_vers);
@@ -522,17 +577,20 @@ cc_int_context_create_ccache( cc_context_t context,
     request_header->name_len = htonl(strlen(name) + 1);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
+
     request_header->principal_offset = htonl(blob_pos);
     request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -544,8 +602,14 @@ cc_int_context_create_ccache( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -557,9 +621,9 @@ cc_int_context_create_default_ccache( cc_context_t context,
 {
     cc_uint32          blob_pos;
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ccache_create_default_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_create_default_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ccache_create_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -579,26 +643,27 @@ cc_int_context_create_default_ccache( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_DEFAULT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_context->handle);
     request_header->version = htonl(cred_vers);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
+
     request_header->principal_offset = htonl(blob_pos);
     request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_default_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -610,8 +675,14 @@ cc_int_context_create_default_ccache( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -623,9 +694,9 @@ cc_int_context_create_new_ccache( cc_context_t context,
 {
     cc_uint32          blob_pos;
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ccache_create_unique_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ccache_create_unique_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ccache_create_resp_t *response_header;
     cc_uint32          type;
     cc_int32           code;
@@ -645,26 +716,27 @@ cc_int_context_create_new_ccache( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_UNIQUE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_context->handle);
     request_header->version = htonl(cred_vers);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
-    if (code != ccNoError) {
-        cci_msg_destroy(request);
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
+
     request_header->principal_offset = htonl(blob_pos);
     request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_unique_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = htonl(response->type);
     if (type == ccmsg_NACK) {
@@ -676,8 +748,14 @@ cc_int_context_create_new_ccache( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
  
@@ -687,9 +765,9 @@ cc_int_context_lock( cc_context_t context,
                      cc_uint32 block )
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ctx_lock_t   *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_lock_t   *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -709,17 +787,20 @@ cc_int_context_lock( cc_context_t context,
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_LOCK, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_context->handle);
     request_header->lock_type = htonl(lock_type);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_lock_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -732,8 +813,14 @@ cc_int_context_lock( cc_context_t context,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+    
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -741,9 +828,9 @@ cc_int32
 cc_int_context_unlock( cc_context_t context )
 {
     cc_int_context_t   int_context;
-    cc_msg_t           *request;
-    ccmsg_ctx_unlock_t *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_unlock_t *request_header = NULL;
+    cc_msg_t           *response = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -760,16 +847,19 @@ cc_int_context_unlock( cc_context_t context )
         return ccErrNoMem;
 
     code = cci_msg_new(ccmsg_CTX_UNLOCK, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_unlock_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -780,8 +870,14 @@ cc_int_context_unlock( cc_context_t context )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -794,10 +890,11 @@ cc_int_context_clone( cc_context_t      inContext,
 {
     cc_int_context_t   int_context;
     static char        vendor_st[128] = "";
-    cc_msg_t           *request;
-    ccmsg_ctx_clone_t  *request_header;
-    cc_msg_t           *response;
+    cc_msg_t           *request = NULL;
+    ccmsg_ctx_clone_t  *request_header = NULL;
+    cc_msg_t           *response = NULL;
     ccmsg_ctx_clone_resp_t *response_header;
+    char               *string = NULL;
     cc_uint32          type;
     cc_int32           code;
 
@@ -831,14 +928,17 @@ cc_int_context_clone( cc_context_t      inContext,
     request_header->in_version = htonl(requestedVersion);
 
     code = cci_msg_new(ccmsg_INIT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_clone_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -850,11 +950,9 @@ cc_int_context_clone( cc_context_t      inContext,
         code = cc_int_context_new(outContext, ntohll(response_header->out_ctx), ntohl(response_header->out_version));
 
         if (!vendor_st[0]) {
-            char * string;
             code = cci_msg_retrieve_blob(response, ntohl(response_header->vendor_offset), ntohl(response_header->vendor_length), &string);
             strncpy(vendor_st, string, sizeof(vendor_st)-1);
             vendor_st[sizeof(vendor_st)-1] = '\0';
-            free(string);
         } 
         *vendor = vendor_st;
 
@@ -862,8 +960,16 @@ cc_int_context_clone( cc_context_t      inContext,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+    
+  cleanup:
+    if (string)
+       free(string);
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
index f61d0ade84e32093862369b8dde51e7a079bfc9b..3cdab875a38ae14e21010a21b84976126a2261ad 100644 (file)
@@ -90,9 +90,9 @@ cc_int32
 cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
 {
     cc_int_credentials_iterator_t int_iter;
-    cc_msg_t                   *request;
-    ccmsg_creds_iterator_release_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_creds_iterator_release_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -112,14 +112,17 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
     request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CREDS_ITERATOR_RELEASE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_release_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = htonl(response->type);
     if (type == ccmsg_NACK) {
@@ -130,8 +133,14 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
 
     free(int_iter->functions);
     free(int_iter);
@@ -143,9 +152,9 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
                                   cc_credentials_t * credentials )
 {
     cc_int_credentials_iterator_t int_iter;
-    cc_msg_t                   *request;
-    ccmsg_creds_iterator_next_t *request_header;
-    cc_msg_t                   *response;
+    cc_msg_t                   *request = NULL;
+    ccmsg_creds_iterator_next_t *request_header = NULL;
+    cc_msg_t                   *response = NULL;
     cc_uint32                  type;
     cc_int32                   code;
 
@@ -165,14 +174,17 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
     request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CREDS_ITERATOR_NEXT, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_next_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -189,8 +201,14 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
@@ -199,9 +217,9 @@ cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter,
                                   cc_credentials_iterator_t* new_iter)
 {
     cc_int_credentials_iterator_t      int_iter;
-    cc_msg_t                           *request;
-    ccmsg_creds_iterator_clone_t       *request_header;
-    cc_msg_t                           *response;
+    cc_msg_t                           *request = NULL;
+    ccmsg_creds_iterator_clone_t       *request_header = NULL;
+    cc_msg_t                           *response = NULL;
     cc_uint32                          type;
     cc_int32                           code;
 
@@ -220,14 +238,17 @@ cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter,
     request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CREDS_ITERATOR_CLONE, &request);
-    if (code != ccNoError) {
-        free(request_header);
-        return code;
-    }
+    if (code != ccNoError)
+       goto cleanup;
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_clone_t));
+    if (code != ccNoError)
+       goto cleanup;
+    request_header = NULL;
 
     code = cci_perform_rpc(request, &response);
+    if (code != ccNoError)
+       goto cleanup;
 
     type = ntohl(response->type);
     if (type == ccmsg_NACK) {
@@ -239,8 +260,14 @@ cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter,
     } else {
         code = ccErrBadInternalMessage;
     }
-    cci_msg_destroy(request);
-    cci_msg_destroy(response);
+
+  cleanup:
+    if (request_header)
+       free(request_header);
+    if (request)
+       cci_msg_destroy(request);
+    if (response)
+       cci_msg_destroy(response);
     return code;
 }
 
index b7f60dd071c5c2eefdf16fe48a12d4ce56ddd46c..ed053ada57e2c7fa50c1182fb7a35b4ab65a411a 100644 (file)
@@ -289,7 +289,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp)
     cc_uint32 u32;\r
     cc_int32 code;\r
 \r
-    if (msg == NULL || flatpp == NULL)\r
+    if (msg == NULL)\r
         return ccErrBadParam;\r
 \r
     code = cci_msg_calc_size(msg,&msg->flat_len);\r
@@ -305,18 +305,15 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp)
     \r
     cur_pos = msg->flat;\r
 \r
-    u32 = msg->header_len;\r
-    htonl(u32);\r
+    u32 = htonl(msg->header_len);\r
     memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
     cur_pos+=sizeof(cc_uint32);\r
 \r
-    u32 = msg->flat_len;\r
-    htonl(u32);\r
+    u32 = htonl(msg->flat_len);\r
     memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
     cur_pos+=sizeof(cc_uint32);\r
 \r
-    u32 = msg->type;\r
-    htonl(u32);\r
+    u32 = htonl(msg->type);\r
     memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
     cur_pos+=sizeof(cc_uint32);\r
 \r
@@ -324,8 +321,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp)
     memcpy(cur_pos, msg->header, msg->header_len);\r
     cur_pos += msg->header_len;\r
 \r
-    u32 = zero;\r
-    htonl(zero);\r
+    u32 = htonl(zero);\r
     memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*will be magic number later*/\r
     cur_pos += sizeof(cc_uint32);\r
 \r
@@ -342,9 +338,8 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp)
             free(msg->flat);\r
             return code;\r
         }\r
-       u32 = gen_node->len;\r
-       htonl(u32);\r
-        memcpy(cur_pos, &u32, sizeof(cc_uint32));\r
+       u32 = htonl(gen_node->len);\r
+           memcpy(cur_pos, &u32, sizeof(cc_uint32));\r
         cur_pos+=sizeof(cc_uint32);\r
                \r
        /* data already in network order */\r
@@ -353,8 +348,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp)
     }\r
     free(gen_iterator);\r
 \r
-    u32 = zero;\r
-    htonl(zero);\r
+    u32 = htonl(zero);\r
     memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*magic number will go here later*/\r
     cur_pos += sizeof(cc_uint32);\r
 \r
@@ -620,7 +614,7 @@ cci_msg_destroy(cc_msg_t* msg)
     if (msg->flat != NULL) \r
         free(msg->flat);\r
     if (msg->header != NULL)\r
-        free(msg->flat);\r
+        free(msg->header);\r
     cci_generic_list_destroy(msg->data_blobs);\r
     free(msg);\r
     return ccNoError;\r
index 9bb486b6d3dc4bdfcec843f89ba69da0174c2715..73f53f2e4e4ff2b924977b38d2f99ae8832a8600 100644 (file)
@@ -14,7 +14,9 @@ T_MSG = t_msg.exe
 \r
 T_SERVER = t_server.exe\r
 \r
-all:  $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)\r
+T_CCAPI = t_ccapi.exe\r
+\r
+all:  $(T_CCAPI) $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)\r
 \r
 ntccrpc_c.c ntccrpc_s.c ntccrpc.h: ntccrpc.idl ntccrpc.acf\r
        midl ntccrpc.idl /acf ntccrpc.acf\r
@@ -42,6 +44,9 @@ $(T_MSG): t_msg.obj $(CC_SERVER_LIB) $(CC_COMMON_LIB)
 $(T_SERVER): t_server.obj $(CC_SERVER_LIB) $(CC_COMMON_LIB)\r
        $(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)\r
 \r
+$(T_CCAPI): t_ccapi.obj $(CC_API_LIB)\r
+       $(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)\r
+\r
 clean:\r
        del *.exe *.dll *.lib *.exp *.obj ntccrpc_c.c ntccrpc_s.c ntccrpc.h\r
 \r
index db0b63aec5ca9debe29b78e90bf9eeed8709daa8..e30801dab625bc6726051a66661117f0d84cd19e 100644 (file)
@@ -78,11 +78,13 @@ int cc_rpc_cleanup(void) {
 }\r
 \r
 cc_int32 cci_set_thread_session_id(unsigned char * client_name, LUID luid) {\r
-\r
+    return 0;\r
 }\r
 \r
 void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid) {\r
-\r
+    client_name[0] = '\0';\r
+    pluid->HighPart = 0;\r
+    pluid->LowPart = 0;\r
 }\r
 \r
 \r
@@ -97,14 +99,14 @@ void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid
 \r
 cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)\r
 {\r
-    __int32 rpc_code;\r
+    cc_int32 code;\r
     unsigned char client_name[256];\r
     LUID luid;\r
     struct __LUID __luid;\r
     unsigned char out_buf[MAXMSGLEN];\r
     __int32  out_len = MAXMSGLEN;\r
 \r
-    if (!cc_rpc_init())\r
+    if (cc_rpc_init())\r
        return -1;\r
 \r
     cci_get_thread_session_id(client_name, sizeof(client_name), &luid);\r
@@ -112,9 +114,28 @@ cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)
     __luid.HighPart = luid.HighPart;\r
     __luid.LowPart  = luid.LowPart;\r
 \r
-    rpc_code = ccapi_Message(hRpcBinding, client_name, __luid, \r
+    /* flatten response */\r
+    code = cci_msg_flatten(request, NULL);\r
+    if (code)\r
+       goto cleanup;\r
+\r
+    RpcTryExcept {\r
+       code = ccapi_Message(hRpcBinding, client_name, __luid, \r
                             request->flat, request->flat_len, \r
                             out_buf, &out_len);\r
+    } \r
+    RpcExcept(1) {\r
+       code = RpcExceptionCode();\r
+    }\r
+    RpcEndExcept;\r
+    if (code)\r
+       goto cleanup;\r
+\r
+    /* unflatten message */\r
+    code = cci_msg_unflatten(out_buf, out_len, response);\r
+    if (code)\r
+       goto cleanup;\r
 \r
-    return rpc_code;\r
+  cleanup:\r
+    return code;\r
 }\r
index 5ce8e6ebe84b0f3eed955b96039ca1134d1ded00..34d3299028193a57eb01ea49fa95bbd6f8be4d23 100644 (file)
@@ -1,5 +1,4 @@
 \r
-\r
 #include <windows.h>\r
 #include "msg.h"\r
 #include "marshall.h"\r
@@ -15,6 +14,9 @@
 \r
 #define SVCNAME "MIT_CCAPI_NT_Service"\r
 \r
+HANDLE hMainThread = 0;\r
+HANDLE WaitToTerminate = 0;\r
+\r
 SERVICE_STATUS_HANDLE h_service_status = NULL;\r
 SERVICE_STATUS service_status;\r
 FILE * logfile = NULL;\r
@@ -72,7 +74,8 @@ void service_start(DWORD argc, LPTSTR * argv) {
                                  NULL);\r
 \r
     if (status != RPC_S_OK) {\r
-        return;\r
+       if (logfile) fprintf(logfile, "service_start RpcServerUseProtseq = 0x%x\n", status);\r
+        goto cleanup;\r
     }\r
 \r
     report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
@@ -80,21 +83,27 @@ void service_start(DWORD argc, LPTSTR * argv) {
     status = RpcServerRegisterIf(portable_ccapi_v1_0_s_ifspec,\r
                                  0, 0);\r
 \r
-    if (status != RPC_S_OK)\r
-        return;\r
+    if (status != RPC_S_OK) {\r
+       if (logfile) fprintf(logfile, "service_start RpcServerRegisterIf = 0x%x\n", status);\r
+        goto cleanup;\r
+    }\r
 \r
     report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
 \r
     status = RpcServerInqBindings(&bv);\r
 \r
-    if (status != RPC_S_OK)\r
-        return;\r
+    if (status != RPC_S_OK) {\r
+       if (logfile) fprintf(logfile, "service_start RpcServerInqBindings = 0x%x\n", status);\r
+        goto cleanup;\r
+    }\r
 \r
     status = RpcEpRegister(portable_ccapi_v1_0_s_ifspec,\r
                            bv, 0, 0);\r
 \r
-    if (status != RPC_S_OK)\r
-        return;\r
+    if (status != RPC_S_OK) {\r
+       if (logfile) fprintf(logfile, "service_start RpcEpRegister = 0x%x\n", status);\r
+        goto cleanup;\r
+    }\r
 \r
     report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
 \r
@@ -102,32 +111,37 @@ void service_start(DWORD argc, LPTSTR * argv) {
                                        RPC_C_AUTHN_WINNT,\r
                                        0, 0);\r
 \r
-    if (status != RPC_S_OK)\r
-        return;\r
+    if (status != RPC_S_OK) {\r
+       if (logfile) fprintf(logfile, "service_start RpcServerRegisterAuthInfo = 0x%x\n", status);\r
+        goto cleanup;\r
+    }\r
 \r
     report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
 \r
-    status = RpcServerListen(1,\r
+    status = RpcServerListen(2,\r
                              RPC_C_LISTEN_MAX_CALLS_DEFAULT,\r
                              TRUE);\r
 \r
-    if (status != RPC_S_OK)\r
-        return;\r
+    if (status != RPC_S_OK) {\r
+       if (logfile) fprintf(logfile, "service_start RpcServerListen = 0x%x\n", status);\r
+        goto cleanup;\r
+    }\r
 \r
     report_status(SERVICE_RUNNING, NO_ERROR, 0);\r
 \r
-    begin_log();\r
 \r
+    if (logfile) fprintf(logfile, "service_start calling RpcMgmtWaitServerListen\n");\r
     status = RpcMgmtWaitServerListen();\r
+    if (logfile) fprintf(logfile, "service_start RpcMgmtWaitServerListen = 0x%x\n", status);\r
 \r
-    end_log();\r
-\r
+  cleanup:\r
     RpcEpUnregister(portable_ccapi_v1_0_s_ifspec, bv, 0);\r
 \r
     RpcBindingVectorFree(&bv);\r
 }\r
 \r
 void service_stop(void) {\r
+    if (logfile) fprintf(logfile, "service_stop\n");\r
     RpcMgmtStopServerListening(0);\r
 }\r
 \r
@@ -292,6 +306,8 @@ __int32 ccapi_Message(
     cc_session_info_t * session_info;\r
     cc_int32            code;\r
 \r
+    if (logfile) fprintf(logfile, "ccapi_Message\n");\r
+\r
     if ( ccs_serv_initialize() != ccNoError ) {\r
        code = ccErrServerUnavailable;\r
        goto done;\r
@@ -390,6 +406,8 @@ void WINAPI service_control(DWORD ctrl_code) {
 \r
 void WINAPI service_main(DWORD argc, LPTSTR * argv) {\r
 \r
+    begin_log();\r
+\r
     h_service_status = RegisterServiceCtrlHandler( _T(SVCNAME), service_control);\r
 \r
     if (!h_service_status)\r
@@ -412,6 +430,8 @@ void WINAPI service_main(DWORD argc, LPTSTR * argv) {
     if (h_service_status) {\r
         report_status(SERVICE_STOPPED, NO_ERROR, 0);\r
     }\r
+\r
+    end_log();\r
 }\r
 \r
 \r
@@ -620,8 +640,16 @@ ParseStandardArgs(int argc, char* argv[])
     return FALSE;\r
 }\r
 \r
-int main(int argc, char ** argv) {\r
+DWORD __stdcall Main_thread(void* notUsed)\r
+{\r
+    char * argv[2] = {SVCNAME, NULL};\r
+    begin_log();\r
+    service_start(1, (LPTSTR*)argv);\r
+    end_log();\r
+    return(0);\r
+}\r
 \r
+int main(int argc, char ** argv) {\r
     SERVICE_TABLE_ENTRY dispatch_table[] = {\r
         { _T(SVCNAME), (LPSERVICE_MAIN_FUNCTION) service_main },\r
         { NULL, NULL }\r
@@ -631,8 +659,21 @@ int main(int argc, char ** argv) {
        return 0;\r
 \r
     if (!StartServiceCtrlDispatcher(dispatch_table)) {\r
-        fprintf(stderr, "Can't start service control dispatcher\n");\r
+        LONG status = GetLastError();\r
+        if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)\r
+        {\r
+            DWORD tid;\r
+            hMainThread = CreateThread(NULL, 0, Main_thread, 0, 0, &tid);\r
+\r
+            printf("Hit <Enter> to terminate MIT CCAPI Server\n");\r
+            getchar();\r
+           service_stop();\r
+       }\r
     }\r
 \r
+    if ( hMainThread ) {\r
+       WaitForSingleObject( hMainThread, INFINITE );\r
+       CloseHandle( hMainThread );\r
+    }\r
     return 0;\r
 }\r