summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Filenko <ivan.filenko@protonmail.com>2018-01-24 01:42:40 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-01 11:05:45 +0100
commit36fd25fa0572403ff32645611e1993de25422182 (patch)
tree836387fa6e7705b40e34c5d3710d53abf7d01cf1 /src
parentccf64e5f222a51349d5d81784c869ab2b940c4d1 (diff)
downloadandroid-node-v8-36fd25fa0572403ff32645611e1993de25422182.tar.gz
android-node-v8-36fd25fa0572403ff32645611e1993de25422182.tar.bz2
android-node-v8-36fd25fa0572403ff32645611e1993de25422182.zip
src: free memory before re-setting URLHost value
Fixes: https://github.com/nodejs/node/issues/18302 PR-URL: https://github.com/nodejs/node/pull/18357 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src')
-rw-r--r--src/node_url.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/node_url.cc b/src/node_url.cc
index 853a23d40d..cac2831af6 100644
--- a/src/node_url.cc
+++ b/src/node_url.cc
@@ -92,6 +92,16 @@ class URLHost {
Value value_;
HostType type_ = HostType::H_FAILED;
+ inline void Reset() {
+ using string = std::string;
+ switch (type_) {
+ case HostType::H_DOMAIN: value_.domain.~string(); break;
+ case HostType::H_OPAQUE: value_.opaque.~string(); break;
+ default: break;
+ }
+ type_ = HostType::H_FAILED;
+ }
+
// Setting the string members of the union with = is brittle because
// it relies on them being initialized to a state that requires no
// destruction of old data.
@@ -101,23 +111,20 @@ class URLHost {
// These helpers are the easiest solution but we might want to consider
// just not forcing strings into an union.
inline void SetOpaque(std::string&& string) {
+ Reset();
type_ = HostType::H_OPAQUE;
new(&value_.opaque) std::string(std::move(string));
}
inline void SetDomain(std::string&& string) {
+ Reset();
type_ = HostType::H_DOMAIN;
new(&value_.domain) std::string(std::move(string));
}
};
URLHost::~URLHost() {
- using string = std::string;
- switch (type_) {
- case HostType::H_DOMAIN: value_.domain.~string(); break;
- case HostType::H_OPAQUE: value_.opaque.~string(); break;
- default: break;
- }
+ Reset();
}
#define ARGS(XX) \