Skip to content

Commit 84936e9

Browse files
committed
8292586: simplify cleanups in NTLMAuthSequence getCredentialsHandle
Reviewed-by: michaelm
1 parent 259ba86 commit 84936e9

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/java.base/windows/native/libnet/NTLMAuthSequence.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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
7676
CredHandle *pCred;
7777
TimeStamp ltime;
7878
jboolean isCopy;
79-
SECURITY_STATUS ss;
79+
SECURITY_STATUS ss = SEC_E_INTERNAL_ERROR;
8080

8181
if (user != 0) {
8282
pUser = JNU_GetStringPlatformChars(env, user, &isCopy);
@@ -86,31 +86,19 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
8686
if (domain != 0) {
8787
pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy);
8888
if (pDomain == NULL) {
89-
if (pUser != NULL)
90-
JNU_ReleaseStringPlatformChars(env, user, pUser);
91-
return 0; // pending Exception
89+
goto cleanup;
9290
}
9391
}
9492
if (password != 0) {
9593
pPassword = JNU_GetStringPlatformChars(env, password, &isCopy);
9694
if (pPassword == NULL) {
97-
if(pUser != NULL)
98-
JNU_ReleaseStringPlatformChars(env, user, pUser);
99-
if(pDomain != NULL)
100-
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
101-
return 0; // pending Exception
95+
goto cleanup;
10296
}
10397
}
10498
pCred = (CredHandle *)malloc(sizeof (CredHandle));
10599
if (pCred == NULL) {
106100
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
107-
if (pUser != NULL)
108-
JNU_ReleaseStringPlatformChars(env, user, pUser);
109-
if (pPassword != NULL)
110-
JNU_ReleaseStringPlatformChars(env, password, pPassword);
111-
if (pDomain != NULL)
112-
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
113-
return NULL;
101+
goto cleanup;
114102
}
115103

116104
if ( ((pUser != NULL) || (pPassword != NULL)) || (pDomain != NULL)) {
@@ -145,14 +133,15 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
145133
);
146134

147135
/* Release resources held by JNU_GetStringPlatformChars */
136+
cleanup:
148137
if (pUser != NULL)
149138
JNU_ReleaseStringPlatformChars(env, user, pUser);
150139
if (pPassword != NULL)
151140
JNU_ReleaseStringPlatformChars(env, password, pPassword);
152141
if (pDomain != NULL)
153142
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
154143

155-
if (ss == 0) {
144+
if (ss == SEC_E_OK) {
156145
return (jlong) pCred;
157146
} else {
158147
return 0;

0 commit comments

Comments
 (0)