Index: base/openssl_util.h |
diff --git a/base/openssl_util.h b/base/openssl_util.h |
index 1d290ae3ad0cd6dcb13206d943961ceb75bd2a8b..366c00c1f98ef0ddd61696ee5c682c2235a3dd24 100644 |
--- a/base/openssl_util.h |
+++ b/base/openssl_util.h |
@@ -16,10 +16,17 @@ namespace base { |
template <typename T, void (*destructor)(T*)> |
class ScopedOpenSSL { |
public: |
- explicit ScopedOpenSSL(T* ptr_) : ptr_(ptr_) { } |
+ ScopedOpenSSL() : ptr_(NULL) { } |
+ explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } |
~ScopedOpenSSL() { if (ptr_) (*destructor)(ptr_); } |
T* get() const { return ptr_; } |
+ void reset(T* ptr) { |
+ if (ptr != ptr_) { |
+ if (ptr_) (*destructor)(ptr_); |
+ ptr_ = ptr; |
+ } |
+ } |
private: |
T* ptr_; |
@@ -72,8 +79,27 @@ class ScopedOpenSSLSafeSizeBuffer { |
void EnsureOpenSSLInit(); |
// Drains the OpenSSL ERR_get_error stack. On a debug build the error codes |
-// are send to VLOG(1), on a release build they are disregarded. |
-void ClearOpenSSLERRStack(); |
+// are send to VLOG(1), on a release build they are disregarded. In most |
+// cases you should pass FROM_HERE as the |location|. |
+void ClearOpenSSLERRStack(const tracked_objects::Location& location); |
+ |
+// Place an instance of this class on the call stack to automatically clear |
+// the OpenSSL error stack on function exit. Note any diagnostic will be emitted |
+// with the location of construction, as it's not possible to track the callsite |
+// of the destructor. |
+class OpenSSLErrStackTracer { |
+ public: |
+ explicit OpenSSLErrStackTracer(const tracked_objects::Location& location) |
+ : location_(location) { |
+ EnsureOpenSSLInit(); |
+ } |
+ ~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(location_); } |
+ |
+ private: |
+ const tracked_objects::Location location_; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); |
+}; |
} // namespace base |