Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak issue. #3

Merged
merged 4 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cpp-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ jobs:
- name: check ASanh
run: |
cmake --build build-ASan
export ASAN_OPTIONS="detect_stack_use_after_return=true detect_leaks=1 strict_string_checks=1 check_initialization_order=1 strict_init_order=1 halt_on_error=0"
export ASAN_OPTIONS="detect_stack_use_after_return=true detect_leaks=1 strict_string_checks=1 check_initialization_order=1 strict_init_order=1 detect_container_overflow=0 detect_container_overflow=0"
pushd build-ASan
ctest
ctest --output-on-failure
popd

- name: check UBSanh
Expand Down
4 changes: 2 additions & 2 deletions include/goofit/PDFs/SumPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class SumPdf : public DataPdf {
mutable bool m_updated;
thrust::host_vector<fptype> cached_sumV;
std::vector<Variable *> _weights;
BinnedDataSet *dataset = nullptr;
BinnedDataSet *dataset_backup = nullptr;
std::shared_ptr<BinnedDataSet> dataset;
std::shared_ptr<BinnedDataSet> dataset_backup;
};

#endif
11 changes: 6 additions & 5 deletions src/PDFs/SumPdf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ void SumPdf::copyHistogramToDevice(const BinnedDataSet *mask, int id) {
}
#include "TRandom.h"
std::unique_ptr<fptype[]> SumPdf::fill_random() {
setData(new BinnedDataSet(*obsBegin()));
BinnedDataSet data(*obsBegin());
setData(&data);
copyParams();
normalise();
int dimensions = 2 + observables.size(); // Bin center (x,y, ...), bin value, and bin volume.
Expand Down Expand Up @@ -437,16 +438,16 @@ BinnedDataSet *SumPdf::getData() {
// [1] Nevent(experiment)
// [2] Bin volume
Variable *obs = observables.front();
dataset = new BinnedDataSet(obs);
dataset = std::unique_ptr<BinnedDataSet>(new BinnedDataSet(obs));
for (unsigned int i = 0; i < numEntries; ++i) {
dataset->setBinContent(i, host_array[i * dimensions + 1]);
}
return dataset;
return dataset.get();
}
void SumPdf::cache() { dataset_backup = getData(); }
void SumPdf::cache() { getData(); dataset_backup = dataset; }
void SumPdf::restore() {
dataset = dataset_backup;
setData(dataset);
setData(dataset.get());
}
int SumPdf::NDF() {
int NnonZeroBins = 0;
Expand Down
2 changes: 0 additions & 2 deletions tests/expFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ TEST(GooFit, testFitResult) {
GooFit::fit(a, b);
EXPECT_NEAR(-1. / 370, a, 1. / 370 * 2e-2);
EXPECT_NEAR(1000, b, 1000 * 2e-2);
int c[3];
std::cout << c[3] << std::endl; // ASan
}