Commit b36e2e85 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Fix memory leaks all over the place (I was dumb when porting to QList)

parent 187c322d
......@@ -101,6 +101,11 @@ class Folder : public File
public:
Folder(const char *name) : File(name, 0), m_children(0) {} //DON'T pass the full path!
~Folder()
{
qDeleteAll(files);
}
uint children() const {
return m_children;
}
......@@ -130,9 +135,11 @@ public:
/// removes a file
void remove(const File *f) {
files.removeAll(const_cast<File*>(f));
const FileSize childSize = f->size();
delete f;
for (Folder *d = this; d; d = d->parent()) {
d->m_size -= f->size();
d->m_size -= childSize;
d->m_children--;
}
}
......
......@@ -95,7 +95,7 @@ void RadialMap::Widget::paintExplodedLabels(QPainter &paint) const
}
}
} else {
for (Segment *segment : *m_map.m_signature) {
for (Segment *segment : m_map.m_signature[0]) {
if (segment->length() > 288) {
list.append(new Label(segment, 0));
......@@ -242,7 +242,8 @@ void RadialMap::Widget::paintExplodedLabels(QPainter &paint) const
if (startX + minTextWidth > width() || textY < fontHeight || middleX < targetX) {
//skip this strut
//**** don't duplicate this code
list.erase(it); //will delete the label and set it to list.current() which _should_ be the next ptr
it = list.erase(it); //will delete the label and set it to list.current() which _should_ be the next ptr
delete label;
break;
}
......@@ -259,7 +260,8 @@ void RadialMap::Widget::paintExplodedLabels(QPainter &paint) const
} else { // left side
if (startX - minTextWidth < 0 || textY > height() || middleX > targetX) {
//skip this strut
list.erase(it); //will delete the label and set it to list.current() which _should_ be the next ptr
it = list.erase(it); //will delete the label and set it to list.current() which _should_ be the next ptr
delete label;
break;
}
......
......@@ -39,8 +39,7 @@
#include "widget.h"
RadialMap::Map::Map(bool summary)
: m_signature(nullptr)
, m_visibleDepth(DEFAULT_RING_DEPTH)
: m_visibleDepth(DEFAULT_RING_DEPTH)
, m_ringBreadth(MIN_RING_BREADTH)
, m_innerRadius(0)
, m_summary(summary)
......@@ -54,13 +53,18 @@ RadialMap::Map::Map(bool summary)
RadialMap::Map::~Map()
{
delete [] m_signature;
for (QList<Segment*> &segments : m_signature) {
qDeleteAll(segments);
}
m_signature.clear();
}
void RadialMap::Map::invalidate()
{
delete [] m_signature;
m_signature = nullptr;
for (QList<Segment*> &segments : m_signature) {
qDeleteAll(segments);
}
m_signature.clear();
m_visibleDepth = Config::defaultRingDepth;
}
......@@ -76,8 +80,12 @@ void RadialMap::Map::make(const Folder *tree, bool refresh)
//**** add some angle bounds checking (possibly in Segment ctor? can I delete in a ctor?)
//**** this is a mess
delete [] m_signature;
m_signature = new QList<Segment*>[m_visibleDepth + 1];
for (QList<Segment*> &segments : m_signature) {
qDeleteAll(segments);
}
m_signature.clear();
m_signature.resize(m_visibleDepth + 1);
m_root = tree;
......@@ -197,7 +205,7 @@ bool RadialMap::Map::build(const Folder * const dir, const uint depth, uint a_st
KFormat().formatByteSize(hiddenSize/hiddenFileCount));
(m_signature + depth)->append(new Segment(new File(QFile::encodeName(s).constData(), hiddenSize), a_start, a_end - a_start, true));
m_signature[depth].append(new Segment(new File(QFile::encodeName(s).constData(), hiddenSize), a_start, a_end - a_start, true));
}
return false;
......@@ -231,7 +239,7 @@ bool RadialMap::Map::resize(const QRectF &newRect)
//resize the pixmap
size += MAP_2MARGIN;
if (m_signature) {
if (!m_signature.isEmpty()) {
setRingBreadth();
paint();
}
......@@ -241,7 +249,7 @@ bool RadialMap::Map::resize(const QRectF &newRect)
void RadialMap::Map::colorise()
{
if (!m_signature || m_signature->isEmpty()) {
if (m_signature.isEmpty()) {
qCDebug(FILELIGHT_LOG) << "no signature yet";
return;
}
......
......@@ -43,7 +43,7 @@ public:
bool resize(const QRectF&);
bool isNull() const {
return (m_signature == nullptr);
return (m_signature.isEmpty());
}
void invalidate();
......@@ -67,7 +67,7 @@ private:
void findVisibleDepth(const Folder *dir, uint currentDepth = 0);
bool build(const Folder* const dir, const uint depth =0, uint a_start =0, const uint a_end =5760);
QList<Segment*> *m_signature;
QVector<QList<Segment*>> m_signature;
const Folder *m_root;
uint m_minSize;
......
......@@ -79,7 +79,7 @@ private:
}
const uint m_angleStart, m_angleSegment;
const File* const m_file;
const File* const m_file = nullptr;
QColor m_pen, m_brush;
bool m_hasHiddenChildren;
const bool m_fake;
......
......@@ -94,7 +94,7 @@ const RadialMap::Segment* RadialMap::Widget::segmentAt(QPointF e) const
e -= m_offset;
if (!m_map.m_signature)
if (m_map.m_signature.isEmpty())
return nullptr;
if (e.x() <= m_map.width() && e.y() <= m_map.height())
......@@ -380,7 +380,6 @@ void RadialMap::Widget::deleteJobFinished(KJob *job)
setEnabled(true);
if (!job->error() && m_toBeDeleted) {
m_toBeDeleted->file()->parent()->remove(m_toBeDeleted->file());
delete m_toBeDeleted->file();
m_toBeDeleted = nullptr;
m_focus = nullptr;
m_map.make(m_tree, true);
......
......@@ -52,6 +52,7 @@ ScanManager::~ScanManager()
m_abort = true;
m_thread->wait();
}
qDeleteAll(m_cache);
//RemoteListers are QObjects and get automatically deleted
}
......
......@@ -100,6 +100,11 @@ SummaryWidget::SummaryWidget(QWidget *parent)
qApp->restoreOverrideCursor();
}
SummaryWidget::~SummaryWidget()
{
qDeleteAll(m_disksFolders);
}
void SummaryWidget::createDiskMaps()
{
DiskList disks;
......@@ -144,6 +149,7 @@ void SummaryWidget::createDiskMaps()
tree->append("used", disk.used);
map->create(tree); //must be done when visible
m_disksFolders.append(tree);
connect(map, &RadialMap::Widget::activated, this, &SummaryWidget::activated);
}
......
......@@ -26,6 +26,8 @@
#include <QWidget>
class Folder;
namespace Filelight {
class SummaryWidget : public QWidget
......@@ -34,12 +36,15 @@ class SummaryWidget : public QWidget
public:
explicit SummaryWidget(QWidget *parent);
~SummaryWidget();
Q_SIGNALS:
void activated(const QUrl&);
private:
void createDiskMaps();
QList<Folder*> m_disksFolders;
};
}
......
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