diff --git a/lemon/glpk.cc b/lemon/glpk.cc --- a/lemon/glpk.cc +++ b/lemon/glpk.cc @@ -522,6 +522,12 @@ cols.clear(); } + void GlpkBase::freeEnv() { + glp_free_env(); + } + + GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper; + // GlpkLp members GlpkLp::GlpkLp() diff --git a/lemon/glpk.h b/lemon/glpk.h --- a/lemon/glpk.h +++ b/lemon/glpk.h @@ -100,6 +100,18 @@ virtual void _clear(); + private: + + static void freeEnv(); + + struct FreeEnvHelper { + ~FreeEnvHelper() { + freeEnv(); + } + }; + + static FreeEnvHelper freeEnvHelper; + public: ///Pointer to the underlying GLPK data structure.