From 3b6f16605c2dcdabca39dd0d61653cc8c72fa72d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 8 Sep 2012 16:48:15 -0400 Subject: Fix bug where recently compiled module happened to receive the same pointer value as the module it replaced, causing dependency tracking not to work properly. Related to #75 diff --git a/src/ModuleCache.cc b/src/ModuleCache.cc index d03d121..c215342 100644 --- a/src/ModuleCache.cc +++ b/src/ModuleCache.cc @@ -75,17 +75,22 @@ Module *ModuleCache::evaluate(const std::string &filename) std::string text((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); print_messages_push(); - + + Module *oldmodule = NULL; cache_entry e = { NULL, cache_id }; if (this->entries.find(filename) != this->entries.end()) { - delete this->entries[filename].module; + oldmodule = this->entries[filename].module; } this->entries[filename] = e; std::string pathname = boosty::stringy(fs::path(filename).parent_path()); lib_mod = dynamic_cast(parse(text.c_str(), pathname.c_str(), false)); + PRINTB_NOCACHE(" compiled module: %p", lib_mod); if (lib_mod) { + // We defer deletion so we can ensure that the new module won't + // have the same address as the old + delete oldmodule; this->entries[filename].module = lib_mod; } else { this->entries.erase(filename); -- cgit v0.10.1