r24282: Try to fix the occasional Samba4 crash in BASE-BENCH-READWRITE, as
authorAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2007 06:26:19 +0000 (06:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:01:35 +0000 (15:01 -0500)
seen in particular on opi.

This looked like a Heimdal problem, but I think it was simply that we
didn't do a talloc_reference() to keep tabs on the memory we were
using, and in between obtaining the pointer and using it, it was
assigned to unrelated memory.

Andrew Bartlett
(This used to be commit a650ad8b37d58ba64458a33313714d1abfc4850b)

source4/auth/credentials/credentials_krb5.c
source4/auth/gensec/gensec_gssapi.c

index ab850c1307d13a3ec2c3c830f929b7e1d6a9f6aa..2b5a5fe7f16531fb344da260714190533680dcc7 100644 (file)
@@ -259,7 +259,8 @@ int cli_credentials_get_ccache(struct cli_credentials *cred,
                cli_credentials_set_machine_account(cred);
        }
 
-       if (cred->ccache_obtained >= cred->ccache_threshold) {
+       if (cred->ccache_obtained >= cred->ccache_threshold && 
+           cred->ccache_obtained > CRED_UNINITIALISED) {
                *ccc = cred->ccache;
                return 0;
        }
@@ -298,7 +299,7 @@ void cli_credentials_invalidate_client_gss_creds(struct cli_credentials *cred,
         * any cached credentials are now invalid */
        if (obtained >= cred->client_gss_creds_obtained) {
                if (cred->client_gss_creds_obtained > CRED_UNINITIALISED) {
-                       talloc_free(cred->client_gss_creds);
+                       talloc_unlink(cred, cred->client_gss_creds);
                        cred->client_gss_creds = NULL;
                }
                cred->client_gss_creds_obtained = CRED_UNINITIALISED;
@@ -319,7 +320,7 @@ void cli_credentials_invalidate_ccache(struct cli_credentials *cred,
         * any cached credentials are now invalid */
        if (obtained >= cred->ccache_obtained) {
                if (cred->ccache_obtained > CRED_UNINITIALISED) {
-                       talloc_free(cred->ccache);
+                       talloc_unlink(cred, cred->ccache);
                        cred->ccache = NULL;
                }
                cred->ccache_obtained = CRED_UNINITIALISED;
@@ -350,7 +351,8 @@ int cli_credentials_get_client_gss_creds(struct cli_credentials *cred,
        OM_uint32 maj_stat, min_stat;
        struct gssapi_creds_container *gcc;
        struct ccache_container *ccache;
-       if (cred->client_gss_creds_obtained >= cred->client_gss_creds_threshold) {
+       if (cred->client_gss_creds_obtained >= cred->client_gss_creds_threshold && 
+           cred->client_gss_creds_obtained > CRED_UNINITIALISED) {
                *_gcc = cred->client_gss_creds;
                return 0;
        }
index a9076845bae4c8f9e84e698989119aad3794fcb3..3c66a032d5948089e460e4e5e0a3ac03daac4323 100644 (file)
@@ -370,7 +370,10 @@ static NTSTATUS gensec_gssapi_client_start(struct gensec_security *gensec_securi
        }
 
        gensec_gssapi_state->client_cred = gcc;
-
+       if (!talloc_reference(gensec_gssapi_state, gcc)) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       
        return NT_STATUS_OK;
 }