diff options
author | Daniel Burrows <dburrows@debian.org> | 2009-07-29 23:16:43 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2009-07-29 23:16:43 -0700 |
commit | 31658b7927c97228bd902dd3817743ed3f7c7195 (patch) | |
tree | aeeab7b40ede933dabb58932f8774465b8d5ba04 /src/main.cc | |
parent | 8d2f93e585284052373c28b7672b8a45f4981e4c (diff) | |
download | aptitude-31658b7927c97228bd902dd3817743ed3f7c7195.tar.gz |
Close the cache when the program exits.
This eliminates the extra flyweight objects that the resolver was
keeping around, by killing the resolver. It turns out that when the
program exits, the flyweight object insists on trying to deref all its
flyweights, but since some still exist, it panics and blows the process
up. (this isn't necessary since THE. PROGRAM. IS. EXITING. but I guess
flyweight didn't get that memo)
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc index eb78ab82..21271ddc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -472,6 +472,24 @@ public: bool requiresLayout() const { return false; } }; +// Ensure that the cache is always closed when main() exits. Without +// this, there might be dangling flyweights hanging around, and those +// can trigger aborts when the static flyweight pool is destroyed. +// +// TBH, I think it might be worth writing our own flyweight stand-in +// to avoid this particular bit of stupid. +struct close_cache_on_exit +{ + close_cache_on_exit() + { + } + + ~close_cache_on_exit() + { + apt_close_cache(); + } +}; + int main(int argc, char *argv[]) { srandom(time(0)); @@ -495,6 +513,8 @@ int main(int argc, char *argv[]) const char * const rootdir = getenv("APT_ROOT_DIR"); apt_preinit(rootdir); + close_cache_on_exit close_on_exit; + char *status_fname=NULL; // The filename to read status information from. string display_format=aptcfg->Find(PACKAGE "::CmdLine::Package-Display-Format", "%c%a%M %p# - %d#"); @@ -1109,9 +1129,13 @@ int main(int argc, char *argv[]) std::string backtrace = e.get_backtrace(); if(!backtrace.empty()) fprintf(stderr, _("Backtrace:\n%s\n"), backtrace.c_str()); + return -1; } + // The cache is closed when the close_on_exit object declared + // above is destroyed. + return 0; } } |