Skip to content

Commit 325936a

Browse files
committed
Fix 'free-nonheap-object' warning
1 parent a1da79c commit 325936a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/ProjectPages.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
#include <assert.h>
4040

4141
ProjectPages::ProjectPages(Qt::LayoutDirection const layout_direction)
42+
: m_refCounter(0)
4243
{
4344
initSubPagesInOrder(layout_direction);
4445
}
4546

4647
ProjectPages::ProjectPages(
47-
std::vector<ImageInfo> const& info,
48+
std::vector<ImageInfo> const &info,
4849
Qt::LayoutDirection const layout_direction)
50+
: m_refCounter(0)
4951
{
5052
initSubPagesInOrder(layout_direction);
5153

@@ -74,8 +76,9 @@ ProjectPages::ProjectPages(
7476
}
7577

7678
ProjectPages::ProjectPages(
77-
std::vector<ImageFileInfo> const& files,
79+
std::vector<ImageFileInfo> const &files,
7880
Pages const pages, Qt::LayoutDirection const layout_direction)
81+
: m_refCounter(0)
7982
{
8083
initSubPagesInOrder(layout_direction);
8184

src/ProjectPages.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
#define PROJECT_PAGES_H_
2121

2222
#include "NonCopyable.h"
23-
#include "RefCountable.h"
2423
#include "ImageMetadata.h"
2524
#include "ImageId.h"
2625
#include "PageId.h"
2726
#include "PageInfo.h"
2827
#include "PageView.h"
2928
#include "BeforeOrAfter.h"
3029
#include "VirtualFunction.h"
30+
#include <QAtomicInt>
3131
#include <QObject>
3232
#include <QMutex>
3333
#include <QString>
@@ -45,7 +45,7 @@ class AbstractRelinker;
4545
class QDomElement;
4646
class QSize;
4747

48-
class ProjectPages : public QObject, public RefCountable
48+
class ProjectPages : public QObject
4949
{
5050
Q_OBJECT
5151
DECLARE_NON_COPYABLE(ProjectPages)
@@ -63,6 +63,19 @@ class ProjectPages : public QObject, public RefCountable
6363

6464
virtual ~ProjectPages();
6565

66+
void ref() const
67+
{
68+
m_refCounter.fetchAndAddRelaxed(1);
69+
}
70+
71+
void unref() const
72+
{
73+
if (m_refCounter.fetchAndAddRelease(-1) == 1)
74+
{
75+
delete this;
76+
}
77+
}
78+
6679
Qt::LayoutDirection layoutDirection() const;
6780

6881
PageSequence toPageSequence(PageView view) const;
@@ -167,6 +180,7 @@ class ProjectPages : public QObject, public RefCountable
167180

168181
PageInfo unremovePageImpl(PageId const& page_id, bool& modified);
169182

183+
mutable QAtomicInt m_refCounter;
170184
mutable QMutex m_mutex;
171185
std::vector<ImageDesc> m_images;
172186
PageId::SubPage m_subPagesInOrder[2];

0 commit comments

Comments
 (0)