8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2f9e2fc commit 37568c0Copy full SHA for 37568c0
src/node.cc
@@ -63,6 +63,7 @@
63
64
#include <string>
65
#include <vector>
66
+#include <list>
67
68
#if defined(NODE_HAVE_I18N_SUPPORT)
69
#include <unicode/uvernum.h>
@@ -4290,34 +4291,24 @@ void Init(int* argc,
4290
4291
4292
4293
struct AtExitCallback {
- AtExitCallback* next_;
4294
void (*cb_)(void* arg);
4295
void* arg_;
4296
};
4297
4298
-static AtExitCallback* at_exit_functions_;
+static std::list<AtExitCallback> at_exit_functions;
4299
4300
4301
// TODO(bnoordhuis) Turn into per-context event.
4302
void RunAtExit(Environment* env) {
4303
- AtExitCallback* p = at_exit_functions_;
4304
- at_exit_functions_ = nullptr;
4305
-
4306
- while (p) {
4307
- AtExitCallback* q = p->next_;
4308
- p->cb_(p->arg_);
4309
- delete p;
4310
- p = q;
+ for (AtExitCallback at_exit : at_exit_functions) {
+ at_exit.cb_(at_exit.arg_);
4311
}
+ at_exit_functions.clear();
4312
4313
4314
4315
void AtExit(void (*cb)(void* arg), void* arg) {
4316
- AtExitCallback* p = new AtExitCallback;
4317
- p->cb_ = cb;
4318
- p->arg_ = arg;
4319
- p->next_ = at_exit_functions_;
4320
- at_exit_functions_ = p;
+ at_exit_functions.push_back(AtExitCallback{cb, arg});
4321
4322
4323