Skip to content

Commit

Permalink
Merge pull request #90 from TristanKnox/memory_leak_fix
Browse files Browse the repository at this point in the history
Fix leak, implement some better practices
  • Loading branch information
Jared-Ponzetti committed Apr 25, 2022
2 parents edd4d2c + 178ec3f commit 5694c31
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
24 changes: 12 additions & 12 deletions backend/src/image_processing/cpp/FlatFieldor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ void FlatFieldor::execute(CommunicationObj* comms, btrgb::ArtObject* images)


//Image set 1-----------------------------------------------------------
btrgb::Image* art1copy = new btrgb::Image("art1copy");
std::unique_ptr<btrgb::Image> art1copy(new btrgb::Image("art1copy"));
cv::Mat copy = btrgb::Image::copyMatConvertDepth(art1->getMat(), CV_32F);
art1copy->initImage(copy);

pixelOperation(height, width, channels, art1, white1, dark1, art1copy);
pixelOperation(height, width, channels, art1, white1, dark1, art1copy.get());
comms->send_progress(0.5, this->get_name());

delete art1copy;
art1copy.reset(nullptr);


//Image set 2-----------------------------------------------------------
btrgb::Image* art2copy = new btrgb::Image("art2copy");
std::unique_ptr<btrgb::Image> art2copy(new btrgb::Image("art2copy"));
cv::Mat copy2 = btrgb::Image::copyMatConvertDepth(art2->getMat(), CV_32F);
art2copy->initImage(copy2);

pixelOperation(height, width, channels, art2, white2, dark2, art2copy);
pixelOperation(height, width, channels, art2, white2, dark2, art2copy.get());
comms->send_progress(1, this->get_name());

delete art2copy;
art2copy.reset(nullptr);


//If there are seperate targets needs to copy to do dead pixel detection
Expand All @@ -104,23 +104,23 @@ void FlatFieldor::execute(CommunicationObj* comms, btrgb::ArtObject* images)


//Copy and delete instantly after operation
btrgb::Image* target1copy = new btrgb::Image("target1copy");
std::unique_ptr<btrgb::Image> target1copy(new btrgb::Image("target1copy"));
cv::Mat tcopy = btrgb::Image::copyMatConvertDepth(target1->getMat(), CV_32F);
target1copy->initImage(tcopy);

pixelOperation(height, width, channels, target1, white1, dark1, target1copy);
pixelOperation(height, width, channels, target1, white1, dark1, target1copy.get());

delete target1copy;
target1copy.reset(nullptr);


//Copy and delete instantly after operation
btrgb::Image* target2copy = new btrgb::Image("target2copy");
std::unique_ptr<btrgb::Image> target2copy(new btrgb::Image("target2copy"));
cv::Mat tcopy2 = btrgb::Image::copyMatConvertDepth(target2->getMat(), CV_32F);
target2copy->initImage(tcopy2);

pixelOperation(height, width, channels, target2, white2, dark2, target2copy);
pixelOperation(height, width, channels, target2, white2, dark2, target2copy.get());

delete target2copy;
target2copy.reset(nullptr);

}

Expand Down
5 changes: 3 additions & 2 deletions backend/src/image_processing/cpp/PixelRegestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ void PixelRegestor::appy_regestration(CommunicationObj* comms, btrgb::Image *img
// cv::imwrite("matches.tiff", imMatches);
cv::Mat matchfloat;
imMatches.convertTo(matchfloat, CV_32FC3, 1.0 / 0xFF);
btrgb::Image *btrgb_matches(new btrgb::Image("matches"));
std::unique_ptr<btrgb::Image> btrgb_matches(new btrgb::Image("matches"));
btrgb_matches->initImage(matchfloat);
comms->send_binary(btrgb_matches, btrgb::FULL);
comms->send_binary(btrgb_matches.get(), btrgb::FULL);
btrgb_matches.reset(nullptr);

// Find homography
prog = this->calc_progress(0.75, (float)cycle, (float)cycle_count);
Expand Down
3 changes: 2 additions & 1 deletion backend/src/image_processing/results/results_formater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class ResultsFormater{
GENERAL, CALIBRATION, VERIFICATION
};

virtual ~ResultsFormater() {}
virtual void write_format(std::ostream &output_stream, CalibrationResults *results, ResultObjType format_type) = 0;

};

#endif // RESULTS_FORMATER_H
#endif // RESULTS_FORMATER_H
6 changes: 3 additions & 3 deletions backend/src/reference_data/ref_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ RefData::~RefData() {
}
for (int row = 0; row < this->row_count; row++) {
for (int col = 0; col < this->col_count; col++) {
delete this->color_patches[row][col];
delete this->color_patches[row][col]; /* ColorPatch pointer */
}
delete this->color_patches[row];
delete[] this->color_patches[row]; /* array of pointers */
}
delete this->color_patches;
delete[] this->color_patches; /* array of double pointers */
}

IlluminantType RefData::get_illuminant(std::string illum_str){
Expand Down
2 changes: 1 addition & 1 deletion backend/src/reference_data/ref_data_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RefDataArray::RefDataArray(int size) {

RefDataArray::~RefDataArray() {
if (nullptr != this->data)
delete data;
delete[] data; /* array of double */
}

double RefDataArray::get_by_index(int index) {
Expand Down
1 change: 1 addition & 0 deletions backend/src/server/process_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void ProcessManager::start_process(std::shared_ptr<BackendProcess> process, std:
std::cout << "Finalizing Process Initialization" << std::endl;
if (nullptr == process) {
this->report_error("ProcessManager", "Unknown RequestType");
return;
}
process->set_coms_obj(coms_obj);
process->set_process_data(request_data);
Expand Down

0 comments on commit 5694c31

Please sign in to comment.