Skip to content

avoid leaving hanging object references in helper functions #44

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

Closed
mattsb42-aws opened this issue Feb 21, 2018 · 3 comments · Fixed by #264
Closed

avoid leaving hanging object references in helper functions #44

mattsb42-aws opened this issue Feb 21, 2018 · 3 comments · Fixed by #264

Comments

@mattsb42-aws
Copy link
Member

The encrypt and decrypt helper functions in the top-level aws_encryption_sdk module currently return the header object from the EncryptionStream objects. To avoid any possibility of those objects not being released for garbage collection because of active reference, we should copy the header object and return the copy.

@abdulsmapara
Copy link
Contributor

@mattsb42-aws
Copy link
Member Author

Hi @abdulsmapara, thanks for the interest!

This is referring to the top-level single-step interfaces for encrypt[1] and decrypt[2]. The concern is that the reference to the attribute on the stream object will keep the stream object around in memory. This is not a concern for the streaming interface because in that case the caller has direct control of the stream object.

Poking around at this a bit today, actually the only thing that we would need to do here is to use copy.deepcopy to copy the header and keyring trace objects from the managed stream before passing them to CryptoResult. It looks like attrs is already handling all the complicated bits. :)

[1]

with StreamEncryptor(**kwargs) as encryptor:
ciphertext = encryptor.read()
return CryptoResult(result=ciphertext, header=encryptor.header, keyring_trace=encryptor.keyring_trace)

[2]
with StreamDecryptor(**kwargs) as decryptor:
plaintext = decryptor.read()
return CryptoResult(result=plaintext, header=decryptor.header, keyring_trace=decryptor.keyring_trace)

@abdulsmapara
Copy link
Contributor

I think this PR should complete the task !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants