]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
env_mirror: instruct EnvMirror whether mirrored Envs should be destroyed env-mirror-leaks
authorSage Weil <sage@redhat.com>
Wed, 28 Sep 2016 17:55:50 +0000 (13:55 -0400)
committerSage Weil <sage@redhat.com>
Wed, 28 Sep 2016 17:55:50 +0000 (13:55 -0400)
The lifecycle rules for Env are frustrating and undocumented.  Notably,
Env::Default() should *not* be freed, but any Env instances we created
should be.

Explicitly instruct EnvMirror whether to clean up child Env instances.
Default to false so that we do not affect existing callers.

Signed-off-by: Sage Weil <sage@redhat.com>
include/rocksdb/utilities/env_mirror.h

index 88c0621a421499a72630319f87caf5d7fb9470c1..091c92a0e8efc55aca2ba4adf01a93489220e96b 100644 (file)
@@ -33,9 +33,21 @@ class WritableFileMirror;
 
 class EnvMirror : public EnvWrapper {
   Env* a_, *b_;
+  bool free_a_, free_b_;
 
  public:
-  EnvMirror(Env* a, Env* b) : EnvWrapper(a), a_(a), b_(b) {}
+  EnvMirror(Env* a, Env* b, bool free_a=false, bool free_b=false)
+    : EnvWrapper(a),
+      a_(a),
+      b_(b),
+      free_a_(free_a),
+      free_b_(free_b) {}
+  ~EnvMirror() {
+    if (free_a_)
+      delete a_;
+    if (free_b_)
+      delete b_;
+  }
 
   Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r,
                            const EnvOptions& options) override;