Fix memory leak from #12664
authorBartosz Nitka <niteria@gmail.com>
Thu, 6 Oct 2016 12:40:24 +0000 (05:40 -0700)
committerBartosz Nitka <niteria@gmail.com>
Fri, 7 Oct 2016 10:07:13 +0000 (03:07 -0700)
commite41b9c614984b63c4660018cecde682453e083e5
tree21237358709a4b236b687dcc5187896695aef245
parentcbe11d5fefefce518c246b470350a5a3bf8efbd6
Fix memory leak from #12664

This fixes the leak with `setProgArgv`. The problem was
that `setProgArgv` would not free the objects pointed
to by `prog_argc`, `prog_argv` when the globals were
changed resulting in a leak.

The only strictly necessary change is in `rts/RtsFlags.c`, but
the code in `System.Environment` was a bit confusing and not
exception safe, so I refactored it.

Test Plan: ./validate

Reviewers: simonmar, ezyang, austin, hvr, bgamari, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2576

GHC Trac Issues: #12664
libraries/base/GHC/Foreign.hs
libraries/base/System/Environment.hs
libraries/base/tests/IO/environment001.hs
libraries/base/tests/IO/environment001.stdout
rts/RtsFlags.c