Fix leak of the Options object in agi::Path and potential overwriting of the config file with an out of date version on shutdown

Originally committed to SVN as r5477.
This commit is contained in:
Thomas Goyne 2011-07-15 17:36:53 +00:00
parent 26695a8cc8
commit c32e372dd4
2 changed files with 8 additions and 7 deletions

View file

@ -22,24 +22,25 @@
#include <vector> #include <vector>
#endif #endif
#include "libaegisub/path.h"
#include "libaegisub/access.h" #include "libaegisub/access.h"
#include "libaegisub/log.h" #include "libaegisub/log.h"
#include "libaegisub/path.h"
#include "libaegisub/option.h" #include "libaegisub/option.h"
#include "libaegisub/option_value.h" #include "libaegisub/option_value.h"
namespace agi { namespace agi {
Path::Path(const std::string &file, const std::string& default_path) Path::Path(const std::string &file, const std::string& default_path)
: path_file(file), : path_file(file)
path_default(default_path) { , path_default(default_path)
opt = new agi::Options(file, default_path); , opt(new agi::Options(file, default_path, Options::FLUSH_SKIP))
{
opt->ConfigUser(); opt->ConfigUser();
LOG_D("agi/path") << "New Path object"; LOG_D("agi/path") << "New Path object";
} }
Path::~Path() { Path::~Path() {
opt->Flush();
} }
@ -71,7 +72,6 @@ void Path::Set(const char *name, const std::string &path) {
} catch (OptionErrorNotFound&) { } catch (OptionErrorNotFound&) {
throw PathErrorNotFound("Invalid path key"); throw PathErrorNotFound("Invalid path key");
} }
} }

View file

@ -22,6 +22,7 @@
#endif #endif
#include <libaegisub/exception.h> #include <libaegisub/exception.h>
#include <libaegisub/scoped_ptr.h>
namespace agi { namespace agi {
@ -97,7 +98,7 @@ private:
void Encode(std::string &path); void Encode(std::string &path);
/// Options object. /// Options object.
Options *opt; scoped_ptr<Options> opt;
/// @brief Locale files /// @brief Locale files
/// @return Locale location /// @return Locale location