Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37568c0

Browse filesBrowse files
danbevItalo A. Casas
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 <info@bnoordhuis.nl> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2f9e2fc commit 37568c0
Copy full SHA for 37568c0

File tree

Expand file treeCollapse file tree

1 file changed

+6
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-15
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+6-15Lines changed: 6 additions & 15 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.