You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 3, 2024. It is now read-only.
The following piece of code causes a lifetime warning about returning a dangling pointer:
class PrivateKey {
// A random class that models a private key.
};
PrivateKey* getPrivateKey() {
return std::unique_ptr<PrivateKey>(new PrivateKey()).release();
}
Is this correct? If we call release on a unique_ptr, I'd assume that the unique pointer no longer retains ownership and a call to the destructor no longer destructs the pointed-to PrivateKey object. I'd assume this is safe (not ideal because the caller would need to delete PrivateKey manually, though, but the pointer should not dangle).