Skip to content

Commit 05d24b9

Browse files
Fix Memory leaks (#1678)
* Refactor to fix #1671 * Add GUI/NonGUI mode to info page * Do not show lock config, if in non-UI mode * Updae Changelog * Correct includes * Ensure key member initialization - RGB Channels * Ensure key member initialization - WebServer * Update RGBChannels * Fix initialization order * Fix key when inserting new logger in LoggerMap, Prepare logBuffer-JSON snapshot view in LoggerManager, Increase buffered loglines to 500 * Fix Memory leak in GrabberWrapper * Fix Memory leak in BlackBorderProcessor * Fix Memory leak in BlackBorderProcessor * use ninja generator under macos * Fix BGEffectHandler destruction * Fix Mdns code * Clear list after applying qDeleteAll * Fix deletion of CecHandler * Fix memory leak caused by wrong buffer allocation * Remove extra pixel consistently * Change mDNS to Qt SmartPointers * Correct removal * Fix usage of _width/_height (they are the output resolution, not the screen resolution) That avoids unnecessary resizing of the output image with every transferFrame call * Move main non Thread Objects to Smart Pointers * Revert "Move main non Thread Objects to Smart Pointers" This reverts commit 26102ca. * Add missing deletes * Revert MdnsBrowser chnage * Revert MdnsBrowser change * Fix memory leaks related standalone grabber * Address CodeQL finding * delete pointer OsxFrameGrabber --------- Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
1 parent 8907d73 commit 05d24b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+437
-339
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Note: The wizard will configure an APIv2 capable bridge always with Entertainmen
5353
- MDNSBrower - Fixed, if timeout while resolving host occurs
5454
- Non image updates ignored blacklisted LEDs (#1634)
5555
- Fixed that Windows OsEvents failed in non-GUI mode (#1671)
56+
- Addressed serious (#1425) and some smaller memory leaks
5657

5758
##### LED-Devices
5859

include/blackborder/BlackBorderProcessor.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#pragma once
1+
#ifndef BLACK_BORDER_PROCESSOR_H
2+
#define BLACK_BORDER_PROCESSOR_H
3+
4+
#include <memory>
25

36
// QT includes
47
#include <QJsonObject>
@@ -24,7 +27,7 @@ namespace hyperion
2427
Q_OBJECT
2528
public:
2629
BlackBorderProcessor(Hyperion* hyperion, QObject* parent);
27-
~BlackBorderProcessor() override;
30+
2831
///
2932
/// Return the current (detected) border
3033
/// @return The current border
@@ -141,7 +144,7 @@ namespace hyperion
141144
QString _detectionMode;
142145

143146
/// The black-border detector
144-
BlackBorderDetector* _detector;
147+
std::unique_ptr<BlackBorderDetector> _detector;
145148

146149
/// The current detected border
147150
BlackBorder _currentBorder;
@@ -162,3 +165,5 @@ namespace hyperion
162165

163166
};
164167
} // end namespace hyperion
168+
169+
#endif // BLACK_BORDER_PROCESSOR_H

include/commandline/ValidatorOption.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class ValidatorOption: public Option
3636
: Option(other), validator(validator)
3737
{}
3838

39+
~ValidatorOption()
40+
{
41+
delete validator;
42+
}
43+
3944
virtual const QValidator *getValidator() const;
4045
virtual bool validate(Parser & parser, QString &value) override;
4146
};

include/grabber/qt/QtGrabber.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ private slots:
113113
int _display;
114114
int _numberOfSDisplays;
115115

116-
int _calculatedWidth;
117-
int _calculatedHeight;
116+
int _screenWidth;
117+
int _screenHeight;
118118
int _src_x;
119119
int _src_y;
120120
int _src_x_max;

include/grabber/x11/X11Grabber.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class X11Grabber : public Grabber , public QAbstractNativeEventFilter
5757
///
5858
/// @brief Apply new width/height values, overwrite Grabber.h implementation as X11 doesn't use width/height, just pixelDecimation to calc dimensions
5959
///
60-
bool setWidthHeight(int width, int height) override { return true; }
60+
bool setWidthHeight(int /*width*/, int /*height*/) override { return true; }
6161

6262
///
6363
/// @brief Apply new pixelDecimation
@@ -109,19 +109,19 @@ class X11Grabber : public Grabber , public QAbstractNativeEventFilter
109109
Picture _srcPicture;
110110
Picture _dstPicture;
111111

112-
int _XRandREventBase;
112+
int _xRandREventBase;
113113

114114
XTransform _transform;
115115

116-
unsigned _calculatedWidth;
117-
unsigned _calculatedHeight;
118-
unsigned _src_x;
119-
unsigned _src_y;
116+
int _screenWidth;
117+
int _screenHeight;
118+
int _src_x;
119+
int _src_y;
120120

121-
bool _XShmAvailable;
122-
bool _XShmPixmapAvailable;
123-
bool _XRenderAvailable;
124-
bool _XRandRAvailable;
121+
bool _xShmAvailable;
122+
bool _xShmPixmapAvailable;
123+
bool _xRenderAvailable;
124+
bool _xRandRAvailable;
125125
bool _isWayland;
126126

127127
Logger * _logger;

include/hyperion/BGEffectHandler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ class BGEffectHandler : public QObject
4343
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
4444
}
4545

46+
///
47+
/// @brief Disconnect from connected signals
48+
/// Disconnect should be done before other priorities invoke methods during shutdown
49+
///
50+
void disconnect()
51+
{
52+
QObject::disconnect(_prioMuxer, &PriorityMuxer::prioritiesChanged, nullptr, nullptr);
53+
QObject::disconnect(_hyperion, nullptr, nullptr, nullptr);
54+
}
55+
4656
///
4757
/// @brief Check, if background effect processing is enabled.
4858
/// @return True, background effect processing is enabled.

include/hyperion/ColorAdjustment.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ class ColorAdjustment
1616
QString _id;
1717

1818
/// The BLACK (RGB-Channel) adjustment
19-
RgbChannelAdjustment _rgbBlackAdjustment;
19+
RgbChannelAdjustment _rgbBlackAdjustment {0, 0, 0, "black"};
2020
/// The WHITE (RGB-Channel) adjustment
21-
RgbChannelAdjustment _rgbWhiteAdjustment;
21+
RgbChannelAdjustment _rgbWhiteAdjustment{255, 255, 255, "white"};
2222
/// The RED (RGB-Channel) adjustment
23-
RgbChannelAdjustment _rgbRedAdjustment;
23+
RgbChannelAdjustment _rgbRedAdjustment {255, 0, 0 , "red"};
2424
/// The GREEN (RGB-Channel) adjustment
25-
RgbChannelAdjustment _rgbGreenAdjustment;
25+
RgbChannelAdjustment _rgbGreenAdjustment {0, 255, 0, "green"};
2626
/// The BLUE (RGB-Channel) adjustment
27-
RgbChannelAdjustment _rgbBlueAdjustment;
27+
RgbChannelAdjustment _rgbBlueAdjustment {0, 0, 255, "blue"};
2828
/// The CYAN (RGB-Channel) adjustment
29-
RgbChannelAdjustment _rgbCyanAdjustment;
29+
RgbChannelAdjustment _rgbCyanAdjustment {0, 255, 255, "cyan"};
3030
/// The MAGENTA (RGB-Channel) adjustment
31-
RgbChannelAdjustment _rgbMagentaAdjustment;
31+
RgbChannelAdjustment _rgbMagentaAdjustment {255, 0, 255, "magenta"};
3232
/// The YELLOW (RGB-Channel) adjustment
33-
RgbChannelAdjustment _rgbYellowAdjustment;
33+
RgbChannelAdjustment _rgbYellowAdjustment {255, 255, 0, "yellow"};
3434

3535
RgbTransform _rgbTransform;
3636
OkhsvTransform _okhsvTransform;

include/hyperion/GrabberWrapper.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QString>
77
#include <QStringList>
88
#include <QMultiMap>
9+
#include <QScopedPointer>
910

1011
#include <utils/Logger.h>
1112
#include <utils/Components.h>
@@ -91,8 +92,8 @@ class GrabberWrapper : public QObject
9192
template <typename Grabber_T>
9293
bool transferFrame(Grabber_T &grabber)
9394
{
94-
unsigned w = grabber.getImageWidth();
95-
unsigned h = grabber.getImageHeight();
95+
int w = grabber.getImageWidth();
96+
int h = grabber.getImageHeight();
9697
if ( _image.width() != w || _image.height() != h)
9798
{
9899
_image.resize(w, h);
@@ -185,7 +186,7 @@ private slots:
185186
Logger * _log;
186187

187188
/// The timer for generating events with the specified update rate
188-
QTimer* _timer;
189+
QScopedPointer<QTimer> _timer;
189190

190191
/// The calculated update rate [ms]
191192
int _updateInterval_ms;

include/mdns/MdnsBrowser.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define MDNS_BROWSER_H
33

44
#include <chrono>
5-
#include <type_traits>
65

76
#include <qmdnsengine/server.h>
87
#include <qmdnsengine/service.h>
@@ -16,6 +15,9 @@
1615
// Qt includes
1716
#include <QObject>
1817
#include <QByteArray>
18+
#include <QMap>
19+
#include <QJsonArray>
20+
#include <QSharedPointer>
1921

2022
// Utility includes
2123
#include <utils/Logger.h>
@@ -24,15 +26,12 @@
2426
namespace {
2527
constexpr std::chrono::milliseconds DEFAULT_DISCOVER_TIMEOUT{ 500 };
2628
constexpr std::chrono::milliseconds DEFAULT_ADDRESS_RESOLVE_TIMEOUT{ 1000 };
27-
28-
} //End of constants
29+
} // End of constants
2930

3031
class MdnsBrowser : public QObject
3132
{
3233
Q_OBJECT
3334

34-
// Run MdnsBrowser as singleton
35-
3635
private:
3736
///
3837
/// @brief Browse for hyperion services in bonjour, constructed from HyperionDaemon
@@ -58,7 +57,6 @@ class MdnsBrowser : public QObject
5857
QMdnsEngine::Service getFirstService(const QByteArray& serviceType, const QString& filter = ".*", const std::chrono::milliseconds waitTime = DEFAULT_DISCOVER_TIMEOUT) const;
5958
QJsonArray getServicesDiscoveredJson(const QByteArray& serviceType, const QString& filter = ".*", const std::chrono::milliseconds waitTime = std::chrono::milliseconds{ 0 }) const;
6059

61-
6260
void printCache(const QByteArray& name = QByteArray(), quint16 type = QMdnsEngine::ANY) const;
6361

6462
public slots:
@@ -109,8 +107,9 @@ private slots:
109107

110108
QMdnsEngine::Server _server;
111109
QMdnsEngine::Cache _cache;
110+
QSharedPointer<QMdnsEngine::Resolver> _resolver;
112111

113-
QMap<QByteArray, QMdnsEngine::Browser*> _browsedServiceTypes;
112+
QMap<QByteArray, QSharedPointer<QMdnsEngine::Browser>> _browsedServiceTypes;
114113
};
115114

116115
#endif // MDNSBROWSER_H

include/mdns/MdnsProvider.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Qt includes
1010
#include <QObject>
1111
#include <QByteArray>
12+
#include <QScopedPointer>
1213

1314
// Utility includes
1415
#include <utils/Logger.h>
@@ -41,11 +42,11 @@ private slots:
4142
/// The logger instance for mDNS-Service
4243
Logger* _log;
4344

44-
QMdnsEngine::Server* _server;
45-
QMdnsEngine::Hostname* _hostname;
45+
QScopedPointer<QMdnsEngine::Server> _server;
46+
QScopedPointer<QMdnsEngine::Hostname> _hostname;
4647

4748
/// map of services provided
48-
QMap<QByteArray, QMdnsEngine::Provider*> _providedServiceTypes;
49+
QMap<QByteArray, QSharedPointer<QMdnsEngine::Provider>> _providedServiceTypes;
4950
};
5051

5152
#endif // MDNSPROVIDER_H

include/utils/Image.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ class Image
1515
{
1616
}
1717

18-
Image(unsigned width, unsigned height) :
18+
Image(int width, int height) :
1919
Image(width, height, Pixel_T())
20-
2120
{
2221
}
2322

@@ -28,7 +27,7 @@ class Image
2827
/// @param height The height of the image
2928
/// @param background The color of the image
3029
///
31-
Image(unsigned width, unsigned height, const Pixel_T background) :
30+
Image(int width, int height, const Pixel_T background) :
3231
_d_ptr(new ImageData<Pixel_T>(width, height, background))
3332
{
3433
}
@@ -78,7 +77,7 @@ class Image
7877
///
7978
/// @return The width of the image
8079
///
81-
inline unsigned width() const
80+
inline int width() const
8281
{
8382
return _d_ptr->width();
8483
}
@@ -88,7 +87,7 @@ class Image
8887
///
8988
/// @return The height of the image
9089
///
91-
inline unsigned height() const
90+
inline int height() const
9291
{
9392
return _d_ptr->height();
9493
}
@@ -111,7 +110,7 @@ class Image
111110
///
112111
/// @return const reference to specified pixel
113112
///
114-
uint8_t blue(unsigned pixel) const
113+
uint8_t blue(int pixel) const
115114
{
116115
return _d_ptr->blue(pixel);
117116
}
@@ -121,23 +120,23 @@ class Image
121120
///
122121
/// @param x The x index
123122
/// @param y The y index
124-
const Pixel_T& operator()(unsigned x, unsigned y) const
123+
const Pixel_T& operator()(int x, int y) const
125124
{
126125
return _d_ptr->operator()(x, y);
127126
}
128127

129128
///
130129
/// @return reference to specified pixel
131130
///
132-
Pixel_T& operator()(unsigned x, unsigned y)
131+
Pixel_T& operator()(int x, int y)
133132
{
134133
return _d_ptr->operator()(x, y);
135134
}
136135

137136
/// Resize the image
138137
/// @param width The width of the image
139138
/// @param height The height of the image
140-
void resize(unsigned width, unsigned height)
139+
void resize(int width, int height)
141140
{
142141
_d_ptr->resize(width, height);
143142
}
@@ -198,12 +197,11 @@ class Image
198197
///
199198
/// @return The index into the underlying data-vector
200199
///
201-
inline unsigned toIndex(unsigned x, unsigned y) const
200+
inline int toIndex(int x, int y) const
202201
{
203202
return _d_ptr->toIndex(x, y);
204203
}
205204

206-
private:
207205
QSharedDataPointer<ImageData<Pixel_T>> _d_ptr;
208206
};
209207

0 commit comments

Comments
 (0)