diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-12-01 01:45:48 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-12-07 22:55:20 +0100 |
commit | a9abc17153921294150cda8df84c5d81faae02c4 (patch) | |
tree | 5baf1f1702641d2413cf528ab1c04531a5e500a2 /src/node_wasi.cc | |
parent | 0a7c874e9c3cb5da99c88ab46e33a648f0b909d2 (diff) | |
download | android-node-v8-a9abc17153921294150cda8df84c5d81faae02c4.tar.gz android-node-v8-a9abc17153921294150cda8df84c5d81faae02c4.tar.bz2 android-node-v8-a9abc17153921294150cda8df84c5d81faae02c4.zip |
wasi: use memory-tracking allocator
This:
- Protects against memory leaks in uvwasi.
- Allows tracking the allocated memory in heap dumps.
PR-URL: https://github.com/nodejs/node/pull/30745
Refs: https://github.com/nodejs/quic/blob/34ee0bc96f804c73cb22b2945a1a78f780938492/src/node_mem.h
Refs: https://github.com/nodejs/quic/pull/126
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_wasi.cc')
-rw-r--r-- | src/node_wasi.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/node_wasi.cc b/src/node_wasi.cc index e9bcb42ad6..39669df490 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -1,6 +1,8 @@ #include "env-inl.h" #include "base_object-inl.h" #include "debug_utils.h" +#include "memory_tracker-inl.h" +#include "node_mem-inl.h" #include "util-inl.h" #include "node.h" #include "uv.h" @@ -85,14 +87,33 @@ WASI::WASI(Environment* env, Local<Object> object, uvwasi_options_t* options) : BaseObject(env, object) { MakeWeak(); + alloc_info_ = MakeAllocator(); + options->allocator = &alloc_info_; CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS); } WASI::~WASI() { uvwasi_destroy(&uvw_); + CHECK_EQ(current_uvwasi_memory_, 0); } +void WASI::MemoryInfo(MemoryTracker* tracker) const { + tracker->TrackField("memory", memory_); + tracker->TrackFieldWithSize("uvwasi_memory", current_uvwasi_memory_); +} + +void WASI::CheckAllocatedSize(size_t previous_size) const { + CHECK_GE(current_uvwasi_memory_, previous_size); +} + +void WASI::IncreaseAllocatedSize(size_t size) { + current_uvwasi_memory_ += size; +} + +void WASI::DecreaseAllocatedSize(size_t size) { + current_uvwasi_memory_ -= size; +} void WASI::New(const FunctionCallbackInfo<Value>& args) { CHECK(args.IsConstructCall()); |