提交 e8f6b294 编写于 作者: I igerasim

8187496: Possible memory leak in java.apple.security.KeychainStore.addItemToKeychain

Reviewed-by: weijun, mullan, ahgross
上级 c08377d2
...@@ -431,12 +431,11 @@ JNIEXPORT jbyteArray JNICALL Java_apple_security_KeychainStore__1getEncodedKeyDa ...@@ -431,12 +431,11 @@ JNIEXPORT jbyteArray JNICALL Java_apple_security_KeychainStore__1getEncodedKeyDa
if (passwordChars == NULL) { if (passwordChars == NULL) {
goto errOut; goto errOut;
} }
passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
// clear the password and release passwordStrRef = CFStringCreateWithCharactersNoCopy(NULL, passwordChars, passwordLen, kCFAllocatorNull);
memset(passwordChars, 0, passwordLen); if (passwordStrRef == NULL) {
(*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars, goto errOut;
JNI_ABORT); }
} }
} }
...@@ -464,7 +463,12 @@ JNIEXPORT jbyteArray JNICALL Java_apple_security_KeychainStore__1getEncodedKeyDa ...@@ -464,7 +463,12 @@ JNIEXPORT jbyteArray JNICALL Java_apple_security_KeychainStore__1getEncodedKeyDa
errOut: errOut:
if (exportedData) CFRelease(exportedData); if (exportedData) CFRelease(exportedData);
if (passwordStrRef) CFRelease(passwordStrRef); if (passwordStrRef) CFRelease(passwordStrRef);
if (passwordChars) {
// clear the password and release
memset(passwordChars, 0, passwordLen);
(*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars,
JNI_ABORT);
}
return returnValue; return returnValue;
} }
...@@ -529,12 +533,11 @@ JNF_COCOA_ENTER(env); ...@@ -529,12 +533,11 @@ JNF_COCOA_ENTER(env);
if (passwordChars == NULL) { if (passwordChars == NULL) {
goto errOut; goto errOut;
} }
passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
// clear the password and release passwordStrRef = CFStringCreateWithCharactersNoCopy(NULL, passwordChars, passwordLen, kCFAllocatorNull);
memset(passwordChars, 0, passwordLen); if (passwordStrRef == NULL) {
(*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars, goto errOut;
JNI_ABORT); }
} }
} }
...@@ -572,7 +575,14 @@ JNF_COCOA_ENTER(env); ...@@ -572,7 +575,14 @@ JNF_COCOA_ENTER(env);
CFRelease(createdItems); CFRelease(createdItems);
} }
errOut: ; errOut:
if (passwordStrRef) CFRelease(passwordStrRef);
if (passwordChars) {
// clear the password and release
memset(passwordChars, 0, passwordLen);
(*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars,
JNI_ABORT);
}
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册