diff --git a/src/sample.cpp b/src/sample.cpp index b95521b0..9fa41c55 100644 --- a/src/sample.cpp +++ b/src/sample.cpp @@ -466,9 +466,16 @@ sample *factory::pop_freelist() { } factory::~factory() { - for (sample *cur = tail_, *next = cur->next_;; cur = next, next = next->next_) { - if (cur != sentinel()) delete cur; - if (!next) break; + sample *cur = tail_.load(); + while (cur) { + sample *next = cur->next_.load(); + + // Only delete samples that are outside of storage area + if (cur != sentinel() && (static_cast(cur) < storage_ || + static_cast(cur) >= storage_ + storage_size_)) + delete cur; + + cur = next; } delete[] storage_; } diff --git a/testing/ext/bench_pushpull.cpp b/testing/ext/bench_pushpull.cpp index a5b7e020..fc7e8ee9 100644 --- a/testing/ext/bench_pushpull.cpp +++ b/testing/ext/bench_pushpull.cpp @@ -32,10 +32,11 @@ TEMPLATE_TEST_CASE("pushpull", "[basic][throughput]", char, double, std::string) auto found_stream_info(lsl::resolve_stream("name", name, 1, 2.0)); REQUIRE(!found_stream_info.empty()); - std::list inlet_list; for (auto n_inlets : param_inlets) { + std::list inlet_list; while (inlet_list.size() < n_inlets) { - inlet_list.emplace_front(found_stream_info[0], 300, false); + lsl::stream_info info_copy(found_stream_info[0]); + inlet_list.emplace_front(info_copy, 300, false); inlet_list.front().open_stream(.5); } std::string suffix(std::to_string(nchan) + "_inlets_" + std::to_string(n_inlets)); @@ -49,7 +50,20 @@ TEMPLATE_TEST_CASE("pushpull", "[basic][throughput]", char, double, std::string) out.push_chunk_multiplexed(data, chunk_size); for (auto &inlet : inlet_list) inlet.flush(); }; + + // Explicitly close and delete the inlets to ensure that they are not + // still in use when the next inlet is created. + for (int i = 0; i < n_inlets; i++) { + inlet_list.back().close_stream(); + inlet_list.pop_back(); + } + } + // Wait until all inlets are closed + // this hangs forever + // while (out.have_consumers()) { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // } } }