File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -466,13 +466,25 @@ sample *factory::pop_freelist() {
466
466
}
467
467
468
468
factory::~factory () {
469
- sample *cur = tail_;
470
- while (cur) {
471
- sample *next = cur->next_ ; // Save next pointer before potentially deleting cur
472
- if (cur != sentinel ()) delete cur;
473
- cur = next;
474
- }
475
- delete[] storage_;
469
+ // get pending samples
470
+ std::vector<sample*> pending;
471
+ sample *cur = tail_.load ();
472
+
473
+ // add them without deleting
474
+ while (cur) {
475
+ if (cur != sentinel ()) {
476
+ pending.push_back (cur);
477
+ }
478
+ sample *next = cur->next_ .load ();
479
+ cur = next;
480
+ }
481
+
482
+ // now delete the samples
483
+ for (sample* s : pending) {
484
+ delete s;
485
+ }
486
+
487
+ delete[] storage_;
476
488
}
477
489
478
490
void factory::reclaim_sample (sample *s) {
You can’t perform that action at this time.
0 commit comments