Skip to content

Commit f796270

Browse files
danbevandrew749
authored andcommitted
src: use std::list for at_exit_functions
This change was suggested by bnoordhuis in the following comment: nodejs/node#9163 (comment) Not including any tests as this is covered by test/addons/at-exit. PR-URL: nodejs/node#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 471a85d commit f796270

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

src/node.cc

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#include <string>
6464
#include <vector>
65+
#include <list>
6566

6667
#if defined(NODE_HAVE_I18N_SUPPORT)
6768
#include <unicode/uvernum.h>
@@ -4429,34 +4430,24 @@ void Init(int* argc,
44294430

44304431

44314432
struct AtExitCallback {
4432-
AtExitCallback* next_;
44334433
void (*cb_)(void* arg);
44344434
void* arg_;
44354435
};
44364436

4437-
static AtExitCallback* at_exit_functions_;
4437+
static std::list<AtExitCallback> at_exit_functions;
44384438

44394439

44404440
// TODO(bnoordhuis) Turn into per-context event.
44414441
void RunAtExit(Environment* env) {
4442-
AtExitCallback* p = at_exit_functions_;
4443-
at_exit_functions_ = nullptr;
4444-
4445-
while (p) {
4446-
AtExitCallback* q = p->next_;
4447-
p->cb_(p->arg_);
4448-
delete p;
4449-
p = q;
4442+
for (AtExitCallback at_exit : at_exit_functions) {
4443+
at_exit.cb_(at_exit.arg_);
44504444
}
4445+
at_exit_functions.clear();
44514446
}
44524447

44534448

44544449
void AtExit(void (*cb)(void* arg), void* arg) {
4455-
AtExitCallback* p = new AtExitCallback;
4456-
p->cb_ = cb;
4457-
p->arg_ = arg;
4458-
p->next_ = at_exit_functions_;
4459-
at_exit_functions_ = p;
4450+
at_exit_functions.push_back(AtExitCallback{cb, arg});
44604451
}
44614452

44624453

0 commit comments

Comments
 (0)