Skip to content
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

Merged
merged 5 commits into from
Dec 13, 2023
Merged

Fix Memory Leaks #734

merged 5 commits into from
Dec 13, 2023

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented Dec 13, 2023

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.

@@ -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);
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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

Suggested change
(*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. */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@waahm7 waahm7 Dec 13, 2023

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.

@waahm7 waahm7 merged commit a8bec86 into main Dec 13, 2023
40 checks passed
@waahm7 waahm7 deleted the fix-memory-leak branch December 13, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants