-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Memory Leaks #734
Fix Memory Leaks #734
Conversation
src/native/credentials.c
Outdated
@@ -73,6 +73,10 @@ struct aws_credentials *aws_credentials_new_from_java_credentials(JNIEnv *env, j | |||
aws_jni_byte_cursor_from_jbyteArray_release(env, session_token, session_token_cursor); | |||
} | |||
|
|||
(*env)->DeleteLocalRef(env, access_key_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check for NULL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to have one place to clean things up even if we error out earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, add a comment here
(*env)->DeleteLocalRef(env, access_key_id); | |
/* When the local reference created by a thread from C, JVM will not be able to clean it up automatically. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://docs.oracle.com/en/java/javase/11/docs/specs/jni/functions.html, yes null is alowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified it to check for null, ensuring consistency, and added a block for clean-up. I didn't move the cursor clean-up as it makes the code messier.
Description of changes:
See #362. JVM fails to create local references created by C threads.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.