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

GC strategies should be double-checked. #19

Open
lunixbochs opened this issue Nov 13, 2014 · 4 comments
Open

GC strategies should be double-checked. #19

lunixbochs opened this issue Nov 13, 2014 · 4 comments

Comments

@lunixbochs
Copy link
Contributor

Any time a C struct is allocated under a Go struct, a GC finalizer should be added to the Go struct with runtime.SetFinalizer, unless "ownership" of the object passes to OpenSSL (which is hard to verify).

For this to work, Go objects need to maintain references to potentially GC-able objects, otherwise OpenSSL allocations still in use when GC runs will cause segfaults as in #10.

This can be made simpler for some objects with a 1:1 mapping by embedding C structs in Go objects and using OpenSSL's _init() instead of _new() functions, like done by the SHA implementation.

Examples:

  • EVP_PKEY_free is called, but maybe needs to be tracked on Ctx when you call a UsePrivateKey() function or set a key on a cert (in theory)
  • When you add a certificate to a context or certificate store, the certificate must be both added to the C structure and the Go object.
@lunixbochs
Copy link
Contributor Author

How do functions like CertificateStore.GetCurrentCert interact with OpenSSL's memory management? Does it really allocate a new X509 structure that needs to be freed? If we dump a cert into a store and pull it back out, is it a pointer to the same address?

@jtolio
Copy link
Member

jtolio commented Nov 13, 2014

further complicating things is that when you get a reference to an underlying C structure from openssl, sometimes it is a new object you have to free, and sometimes it is an object who has a lifetime bound to the parent object and no free of the child object is necessary or needed

@lunixbochs
Copy link
Contributor Author

Yeah, that's why I have TODO on Name GC stuff.

@jtolio
Copy link
Member

jtolio commented Nov 13, 2014

oh, okay got it

merlin-northern added a commit to merlin-northern/openssl that referenced this issue Aug 20, 2020
…_quick_fix

Commenting out not used consts, for OpenSSL v1.1.0 compatibility.
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

No branches or pull requests

2 participants