Skip to content

Commit 37568c0

Browse files
danbevitaloacasas
authored andcommitted
src: use std::list for at_exit_functions
This change was suggested by bnoordhuis in the following comment: #9163 (comment) Not including any tests as this is covered by test/addons/at-exit. PR-URL: #12255 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 2f9e2fc commit 37568c0

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/node.cc

+6-15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
#include <string>
6565
#include <vector>
66+
#include <list>
6667

6768
#if defined(NODE_HAVE_I18N_SUPPORT)
6869
#include <unicode/uvernum.h>
@@ -4290,34 +4291,24 @@ void Init(int* argc,
42904291

42914292

42924293
struct AtExitCallback {
4293-
AtExitCallback* next_;
42944294
void (*cb_)(void* arg);
42954295
void* arg_;
42964296
};
42974297

4298-
static AtExitCallback* at_exit_functions_;
4298+
static std::list<AtExitCallback> at_exit_functions;
42994299

43004300

43014301
// TODO(bnoordhuis) Turn into per-context event.
43024302
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;
4303+
for (AtExitCallback at_exit : at_exit_functions) {
4304+
at_exit.cb_(at_exit.arg_);
43114305
}
4306+
at_exit_functions.clear();
43124307
}
43134308

43144309

43154310
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;
4311+
at_exit_functions.push_back(AtExitCallback{cb, arg});
43214312
}
43224313

43234314

0 commit comments

Comments
 (0)