You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/01/12 17:32:49 UTC
[10/10] mesos git commit: Windows: Fixed memory leak.
Windows: Fixed memory leak.
The environment strings variable block is allocated by the system, and
must be manually freed (according to the docs).
Review: https://reviews.apache.org/r/64961
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ff77d323
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ff77d323
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ff77d323
Branch: refs/heads/master
Commit: ff77d3235f5845192064b0f227918775ee035b01
Parents: 12be4ba
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jan 3 11:40:30 2018 -0800
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Fri Jan 12 09:29:17 2018 -0800
----------------------------------------------------------------------
3rdparty/stout/include/stout/os/windows/environment.hpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/ff77d323/3rdparty/stout/include/stout/os/windows/environment.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/environment.hpp b/3rdparty/stout/include/stout/os/windows/environment.hpp
index f79cbfa..40eee59 100644
--- a/3rdparty/stout/include/stout/os/windows/environment.hpp
+++ b/3rdparty/stout/include/stout/os/windows/environment.hpp
@@ -14,6 +14,7 @@
#define __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__
#include <map>
+#include <memory>
#include <string>
#include <stout/stringify.hpp>
@@ -29,11 +30,13 @@ inline std::map<std::string, std::string> environment()
// Var3=Value3\0
// ...
// VarN=ValueN\0\0
- wchar_t* env = ::GetEnvironmentStringsW();
+ const std::unique_ptr<wchar_t[], decltype(&::FreeEnvironmentStringsW)> env(
+ ::GetEnvironmentStringsW(), &::FreeEnvironmentStringsW);
std::map<std::string, std::string> result;
- for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';) {
- std::wstring entry(env + i);
+ for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';
+ /* incremented below */) {
+ std::wstring entry(&env[i]);
// Increment past the current environment string and null terminator.
i = i + entry.size() + 1;