From: Sage Weil Date: Wed, 28 Sep 2016 17:55:50 +0000 (-0400) Subject: env_mirror: instruct EnvMirror whether mirrored Envs should be destroyed X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bf09c048f3449135339dd52d7bd16820b1a51389;p=rocksdb.git env_mirror: instruct EnvMirror whether mirrored Envs should be destroyed 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 --- diff --git a/include/rocksdb/utilities/env_mirror.h b/include/rocksdb/utilities/env_mirror.h index 88c0621a..091c92a0 100644 --- a/include/rocksdb/utilities/env_mirror.h +++ b/include/rocksdb/utilities/env_mirror.h @@ -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* r, const EnvOptions& options) override;