Skip to content

Commit

Permalink
Fix issues found by AddressSanitizer
Browse files Browse the repository at this point in the history
Fix memcpy overlap in TIFF reader.
Fix memory leaks of SpotRows in control spot panel.
Fix memory leaks of SpotRows in locallab.
Fix memory leak of Glib::ThreadPool in file browser entry.
Fix memory leak of Glib::ThreadPool in thumbnail image updater.
  • Loading branch information
Lawrence37 committed Nov 12, 2023
1 parent f93c3dd commit c5bb1f0
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 250 deletions.
2 changes: 1 addition & 1 deletion rtengine/imageio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ int ImageIO::loadTIFF (const Glib::ustring &fname)

if (samplesperpixel > 3) {
for (int i = 0; i < width; i++) {
memcpy(linebuffer.get() + i * 3 * bitspersample / 8, linebuffer.get() + i * samplesperpixel * bitspersample / 8, 3 * bitspersample / 8);
memmove(linebuffer.get() + i * 3 * bitspersample / 8, linebuffer.get() + i * samplesperpixel * bitspersample / 8, 3 * bitspersample / 8);
}
}
else if (samplesperpixel == 1) {
Expand Down
103 changes: 53 additions & 50 deletions rtgui/controlspotpanel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ void ControlSpotPanel::on_button_delete()
nbSpotChanged_ = true;
selSpotChanged_ = true;
eventType = SpotDeletion;
SpotRow* const delSpotRow = getSpot(selIndex);
std::unique_ptr<SpotRow> const delSpotRow = getSpot(selIndex);
listener->panelChanged(EvLocallabSpotDeleted, delSpotRow->name);
}

Expand All @@ -682,7 +682,7 @@ void ControlSpotPanel::on_button_duplicate()
nbSpotChanged_ = true;
selSpotChanged_ = true;
eventType = SpotDuplication;
SpotRow* const duplSpotRow = getSpot(selIndex);
std::unique_ptr<SpotRow> const duplSpotRow = getSpot(selIndex);
listener->panelChanged(EvLocallabSpotCreated, M("TP_LOCALLAB_EV_DUPL") + " "
+ duplSpotRow->name);
}
Expand Down Expand Up @@ -779,7 +779,7 @@ bool ControlSpotPanel::on_button_visibility(GdkEventButton* event)

// Raise event
visibilityChanged_ = true;
SpotRow* const spotRow = getSpot(getSelectedSpot());
std::unique_ptr<SpotRow> const spotRow = getSpot(getSelectedSpot());

if (row[spots_.isvisible]) {
listener->panelChanged(EvLocallabSpotVisibility, M("TP_LOCALLAB_EV_VIS") + " (" + spotRow->name + ")");
Expand Down Expand Up @@ -896,7 +896,7 @@ void ControlSpotPanel::controlspotChanged()

selSpotChanged_ = true;
eventType = SpotSelection;
SpotRow* const spotRow = getSpot(selIndex);
std::unique_ptr<SpotRow> const spotRow = getSpot(selIndex);

// Image area shall be regenerated if mask or deltaE preview was active when switching spot
if (maskPrevActive || preview_->get_active()) {
Expand Down Expand Up @@ -2535,13 +2535,16 @@ int ControlSpotPanel::getEventType()
return tmp;
}

ControlSpotPanel::SpotRow* ControlSpotPanel::getSpot(const int index)
std::unique_ptr<ControlSpotPanel::SpotRow> ControlSpotPanel::getSpot(const int index)
{
// TODO: Return an std::optional<ControlSpotPanel::SpotRow> after upgrading
// to C++17.

// printf("getSpot: %d\n", index);

MyMutex::MyLock lock(mTreeview);

SpotRow* r = new SpotRow();
std::unique_ptr<SpotRow> r(new SpotRow());

int i = -1;

Expand Down Expand Up @@ -2676,58 +2679,58 @@ void ControlSpotPanel::resetDeltaEPreview()
previewConn_.block(false);
}

void ControlSpotPanel::addControlSpot(SpotRow* newSpot)
void ControlSpotPanel::addControlSpot(const SpotRow &newSpot)
{
// printf("addControlSpot: %d\n", newSpot->name);
// printf("addControlSpot: %d\n", newSpot.name);

MyMutex::MyLock lock(mTreeview);

disableParamlistener(true);
Gtk::TreeModel::Row row = *(treemodel_->append());
row[spots_.mouseover] = false;
row[spots_.name] = newSpot->name;
row[spots_.isvisible] = newSpot->isvisible;
row[spots_.name] = newSpot.name;
row[spots_.isvisible] = newSpot.isvisible;
row[spots_.curveid] = 0; // No associated curve
row[spots_.prevMethod] = newSpot->prevMethod;
row[spots_.shape] = newSpot->shape;
row[spots_.spotMethod] = newSpot->spotMethod;
row[spots_.sensiexclu] = newSpot->sensiexclu;
row[spots_.structexclu] = newSpot->structexclu;
row[spots_.shapeMethod] = newSpot->shapeMethod;
row[spots_.locX] = newSpot->locX;
row[spots_.locXL] = newSpot->locXL;
row[spots_.locY] = newSpot->locY;
row[spots_.locYT] = newSpot->locYT;
row[spots_.centerX] = newSpot->centerX;
row[spots_.centerY] = newSpot->centerY;
row[spots_.circrad] = newSpot->circrad;
row[spots_.qualityMethod] = newSpot->qualityMethod;
row[spots_.transit] = newSpot->transit;
row[spots_.transitweak] = newSpot->transitweak;
row[spots_.transitgrad] = newSpot->transitgrad;
row[spots_.feather] = newSpot->feather;
row[spots_.struc] = newSpot->struc;
row[spots_.thresh] = newSpot->thresh;
row[spots_.iter] = newSpot->iter;
row[spots_.balan] = newSpot->balan;
row[spots_.balanh] = newSpot->balanh;
row[spots_.colorde] = newSpot->colorde;
row[spots_.colorscope] = newSpot->colorscope;
row[spots_.avoidrad] = newSpot->avoidrad;
row[spots_.hishow] = newSpot->hishow;
row[spots_.activ] = newSpot->activ;
row[spots_.blwh] = newSpot->blwh;
row[spots_.recurs] = newSpot->recurs;
row[spots_.laplac] = newSpot->laplac;
row[spots_.deltae] = newSpot->deltae;
row[spots_.scopemask] = newSpot->scopemask;
row[spots_.denoichmask] = newSpot->denoichmask;
row[spots_.shortc] = newSpot->shortc;
row[spots_.lumask] = newSpot->lumask;
//row[spots_.savrest] = newSpot->savrest;
row[spots_.complexMethod] = newSpot->complexMethod;
row[spots_.wavMethod] = newSpot->wavMethod;
row[spots_.avoidgamutMethod] = newSpot->avoidgamutMethod;
row[spots_.prevMethod] = newSpot.prevMethod;
row[spots_.shape] = newSpot.shape;
row[spots_.spotMethod] = newSpot.spotMethod;
row[spots_.sensiexclu] = newSpot.sensiexclu;
row[spots_.structexclu] = newSpot.structexclu;
row[spots_.shapeMethod] = newSpot.shapeMethod;
row[spots_.locX] = newSpot.locX;
row[spots_.locXL] = newSpot.locXL;
row[spots_.locY] = newSpot.locY;
row[spots_.locYT] = newSpot.locYT;
row[spots_.centerX] = newSpot.centerX;
row[spots_.centerY] = newSpot.centerY;
row[spots_.circrad] = newSpot.circrad;
row[spots_.qualityMethod] = newSpot.qualityMethod;
row[spots_.transit] = newSpot.transit;
row[spots_.transitweak] = newSpot.transitweak;
row[spots_.transitgrad] = newSpot.transitgrad;
row[spots_.feather] = newSpot.feather;
row[spots_.struc] = newSpot.struc;
row[spots_.thresh] = newSpot.thresh;
row[spots_.iter] = newSpot.iter;
row[spots_.balan] = newSpot.balan;
row[spots_.balanh] = newSpot.balanh;
row[spots_.colorde] = newSpot.colorde;
row[spots_.colorscope] = newSpot.colorscope;
row[spots_.avoidrad] = newSpot.avoidrad;
row[spots_.hishow] = newSpot.hishow;
row[spots_.activ] = newSpot.activ;
row[spots_.blwh] = newSpot.blwh;
row[spots_.recurs] = newSpot.recurs;
row[spots_.laplac] = newSpot.laplac;
row[spots_.deltae] = newSpot.deltae;
row[spots_.scopemask] = newSpot.scopemask;
row[spots_.denoichmask] = newSpot.denoichmask;
row[spots_.shortc] = newSpot.shortc;
row[spots_.lumask] = newSpot.lumask;
//row[spots_.savrest] = newSpot.savrest;
row[spots_.complexMethod] = newSpot.complexMethod;
row[spots_.wavMethod] = newSpot.wavMethod;
row[spots_.avoidgamutMethod] = newSpot.avoidgamutMethod;
updateParamVisibility();
disableParamlistener(false);

Expand Down
6 changes: 4 additions & 2 deletions rtgui/controlspotpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef _CONTROLSPOTPANEL_H_
#define _CONTROLSPOTPANEL_H_

#include <memory>

#include "../rtengine/coord.h"
#include "editcallbacks.h"
#include "threadutils.h"
Expand Down Expand Up @@ -141,7 +143,7 @@ class ControlSpotPanel:
* @param index The spot index to get params
* @return A SpotRow structure containing params of associated spot
*/
SpotRow* getSpot(const int index);
std::unique_ptr<SpotRow> getSpot(const int index);
/**
* Getter of spots number
*
Expand Down Expand Up @@ -187,7 +189,7 @@ class ControlSpotPanel:
*
* @param newSpot A SpotRow structure containing new spot params
*/
void addControlSpot(SpotRow* newSpot);
void addControlSpot(const SpotRow &newSpot);

// Control spot delete function
/**
Expand Down
Loading

0 comments on commit c5bb1f0

Please sign in to comment.