From 2bcd65ecf6a8505ade08aa39efe41a0361eaf84a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 1 Sep 2005 18:14:04 +0000 Subject: * `nix-env -e' corrupts memory due to incorrect use of iterators. Reported by Rob Vermaas. --- src/nix-env/main.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 4676f0131..96bbce5cf 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -584,23 +584,27 @@ static void uninstallDerivations(Globals & globals, DrvNames & selectors, Path & profile) { UserEnvElems installedElems = queryInstalled(globals.state, profile); + UserEnvElems newElems; for (UserEnvElems::iterator i = installedElems.begin(); i != installedElems.end(); ++i) { DrvName drvName(i->second.name); + bool found = false; for (DrvNames::iterator j = selectors.begin(); j != selectors.end(); ++j) if (j->matches(drvName)) { printMsg(lvlInfo, format("uninstalling `%1%'") % i->second.name); - installedElems.erase(i); + found = true; + break; } + if (!found) newElems.insert(*i); } if (globals.dryRun) return; - createUserEnv(globals.state, installedElems, + createUserEnv(globals.state, newElems, profile, globals.keepDerivations); } -- cgit v1.2.3