Commit 58e49ab5 authored by Tomaz Canabrava's avatar Tomaz Canabrava Committed by Tomaz Canabrava
Browse files

Replace manual memory management with unique_ptr

parent 6fbf8161
......@@ -111,8 +111,6 @@ TerminalImageFilterChain::TerminalImageFilterChain() :
TerminalImageFilterChain::~TerminalImageFilterChain()
{
delete _buffer;
delete _linePositions;
}
void TerminalImageFilterChain::setImage(const Character * const image, int lines, int columns,
......@@ -130,18 +128,12 @@ void TerminalImageFilterChain::setImage(const Character * const image, int lines
decoder.setTrailingWhitespace(true);
// setup new shared buffers for the filters to process on
auto newBuffer = new QString();
auto newLinePositions = new QList<int>();
setBuffer(newBuffer, newLinePositions);
_buffer.reset(new QString());
_linePositions.reset(new QList<int>());
// free the old buffers
delete _buffer;
delete _linePositions;
setBuffer(_buffer.get(), _linePositions.get());
_buffer = newBuffer;
_linePositions = newLinePositions;
QTextStream lineStream(_buffer);
QTextStream lineStream(_buffer.get());
decoder.begin(&lineStream);
for (int i = 0; i < lines; i++) {
......
......@@ -29,6 +29,8 @@
#include <QRegularExpression>
#include <QMultiHash>
#include <memory>
// Konsole
#include "Character.h"
......@@ -394,8 +396,10 @@ public:
private:
Q_DISABLE_COPY(TerminalImageFilterChain)
QString *_buffer;
QList<int> *_linePositions;
/* usually QStrings and QLists are not supposed to be in the heap, here we have a problem:
we need a shared memory space between many filter objeccts, defined by this TerminalImage. */
std::unique_ptr<QString> _buffer;
std::unique_ptr<QList<int>> _linePositions;
};
}
#endif //FILTER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment