8292586: simplify cleanups in NTLMAuthSequence getCredentialsHandle

Reviewed-by: michaelm
This commit is contained in:
Matthias Baesken 2022-08-23 07:31:43 +00:00
parent 259ba86c60
commit 84936e9278

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -76,7 +76,7 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
CredHandle *pCred;
TimeStamp ltime;
jboolean isCopy;
SECURITY_STATUS ss;
SECURITY_STATUS ss = SEC_E_INTERNAL_ERROR;
if (user != 0) {
pUser = JNU_GetStringPlatformChars(env, user, &isCopy);
@ -86,31 +86,19 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
if (domain != 0) {
pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy);
if (pDomain == NULL) {
if (pUser != NULL)
JNU_ReleaseStringPlatformChars(env, user, pUser);
return 0; // pending Exception
goto cleanup;
}
}
if (password != 0) {
pPassword = JNU_GetStringPlatformChars(env, password, &isCopy);
if (pPassword == NULL) {
if(pUser != NULL)
JNU_ReleaseStringPlatformChars(env, user, pUser);
if(pDomain != NULL)
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
return 0; // pending Exception
goto cleanup;
}
}
pCred = (CredHandle *)malloc(sizeof (CredHandle));
if (pCred == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
if (pUser != NULL)
JNU_ReleaseStringPlatformChars(env, user, pUser);
if (pPassword != NULL)
JNU_ReleaseStringPlatformChars(env, password, pPassword);
if (pDomain != NULL)
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
return NULL;
goto cleanup;
}
if ( ((pUser != NULL) || (pPassword != NULL)) || (pDomain != NULL)) {
@ -145,6 +133,7 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
);
/* Release resources held by JNU_GetStringPlatformChars */
cleanup:
if (pUser != NULL)
JNU_ReleaseStringPlatformChars(env, user, pUser);
if (pPassword != NULL)
@ -152,7 +141,7 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
if (pDomain != NULL)
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
if (ss == 0) {
if (ss == SEC_E_OK) {
return (jlong) pCred;
} else {
return 0;