mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 修复内存泄露问题
修复Address Sanitizer检测的内存泄露处 Log: 修复内存泄露问题 Bug: https://pms.uniontech.com/zentao/bug-view-68395.html Change-Id: Ib43b3cd3c37ee1825c04e8fffc7d3e1836a177af
This commit is contained in:
parent
04404a6aa9
commit
a3619cc0bb
@ -65,3 +65,7 @@ endif()
|
||||
|
||||
# bin
|
||||
install(TARGETS ${BIN_NAME} DESTINATION bin)
|
||||
|
||||
# Address Sanitizer 内存错误检测工具,打开下面的编译选项可以看到调试信息,正常运行时不需要这些信息
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O2")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O2")
|
||||
|
@ -96,6 +96,10 @@ const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size, cons
|
||||
layout->setContentsMargins(0, 10 * iconZoom, 0, 10 * iconZoom);
|
||||
calendar->setLayout(layout);
|
||||
pixmap = calendar->grab(calendar->rect());
|
||||
|
||||
delete calendar;
|
||||
calendar = nullptr;
|
||||
|
||||
if (pixmap.size().width() != s) {
|
||||
pixmap = pixmap.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||
, m_sniServicePath(sniServicePath)
|
||||
, m_popupTipsDelayTimer(new QTimer(this))
|
||||
, m_handleMouseReleaseTimer(new QTimer(this))
|
||||
, m_tipsLabel(new TipsWidget)
|
||||
, m_tipsLabel(new TipsWidget(this))
|
||||
{
|
||||
m_popupTipsDelayTimer->setInterval(500);
|
||||
m_popupTipsDelayTimer->setSingleShot(true);
|
||||
@ -145,14 +145,6 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||
initSNIPropertys();
|
||||
}
|
||||
|
||||
SNITrayWidget::~SNITrayWidget()
|
||||
{
|
||||
if(m_tipsLabel != nullptr){
|
||||
m_tipsLabel->deleteLater();
|
||||
m_tipsLabel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QString SNITrayWidget::itemKeyForConfig()
|
||||
{
|
||||
QString key;
|
||||
|
@ -50,7 +50,6 @@ public:
|
||||
|
||||
public:
|
||||
SNITrayWidget(const QString &sniServicePath, QWidget *parent = Q_NULLPTR);
|
||||
virtual ~SNITrayWidget() override;
|
||||
|
||||
QString itemKeyForConfig() override;
|
||||
void setActive(const bool active) override;
|
||||
|
@ -183,11 +183,12 @@ void XEmbedTrayWidget::wrapWindow()
|
||||
}
|
||||
|
||||
auto cookie = xcb_get_geometry(c, m_windowId);
|
||||
QScopedPointer<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR));
|
||||
if (clientGeom.isNull()) {
|
||||
xcb_get_geometry_reply_t *clientGeom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR));
|
||||
if (!clientGeom) {
|
||||
m_valid = false;
|
||||
return;
|
||||
}
|
||||
free(clientGeom);
|
||||
|
||||
//create a container window
|
||||
const auto ratio = devicePixelRatioF();
|
||||
@ -401,9 +402,10 @@ void XEmbedTrayWidget::refershIconImage()
|
||||
}
|
||||
|
||||
auto cookie = xcb_get_geometry(c, m_windowId);
|
||||
QScopedPointer<xcb_get_geometry_reply_t> geom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR));
|
||||
if (geom.isNull())
|
||||
xcb_get_geometry_reply_t *geom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR));
|
||||
if (!geom) {
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_expose_event_t expose;
|
||||
expose.response_type = XCB_EXPOSE;
|
||||
@ -416,12 +418,16 @@ void XEmbedTrayWidget::refershIconImage()
|
||||
xcb_flush(c);
|
||||
|
||||
xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
|
||||
if (!image)
|
||||
if (!image) {
|
||||
free(geom);
|
||||
return;
|
||||
}
|
||||
|
||||
QImage qimage(image->data, image->width, image->height, image->stride, QImage::Format_ARGB32, sni_cleanup_xcb_image, image);
|
||||
if (qimage.isNull())
|
||||
if (qimage.isNull()) {
|
||||
free(geom);
|
||||
return;
|
||||
}
|
||||
|
||||
m_image = qimage.scaled(iconSize * ratio, iconSize * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
m_image.setDevicePixelRatio(ratio);
|
||||
|
@ -69,3 +69,7 @@ add_custom_command(TARGET check
|
||||
)
|
||||
|
||||
add_dependencies(check ${BIN_NAME})
|
||||
|
||||
# Address Sanitizer 内存错误检测工具,打开下面的编译选项可以看到调试信息,正常运行时不需要这些信息
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O2")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O2")
|
||||
|
@ -51,6 +51,6 @@ TEST_F(Test_AppDrag, drag_test)
|
||||
|
||||
drag->exec();
|
||||
|
||||
delete drag;
|
||||
drag = nullptr;
|
||||
delete w;
|
||||
w = nullptr;
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ void Test_FloatingPreview::TearDown()
|
||||
|
||||
TEST_F(Test_FloatingPreview, view_test)
|
||||
{
|
||||
FloatingPreview *view = new FloatingPreview(new QWidget);
|
||||
QWidget *parent = new QWidget;
|
||||
FloatingPreview *view = new FloatingPreview(parent);
|
||||
AppSnapshot *shot = new AppSnapshot(1000);
|
||||
view->trackWindow(shot);
|
||||
|
||||
@ -68,7 +69,7 @@ TEST_F(Test_FloatingPreview, view_test)
|
||||
ASSERT_TRUE(view->m_titleBtn->text().isEmpty());
|
||||
ASSERT_EQ(view->trackedWindow(), shot);
|
||||
|
||||
delete view;
|
||||
view = nullptr;
|
||||
delete parent;
|
||||
parent = nullptr;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,18 @@
|
||||
TestPlugin::TestPlugin()
|
||||
: m_sortKey(0)
|
||||
, m_type(Normal)
|
||||
, m_widget(new QWidget)
|
||||
{
|
||||
}
|
||||
|
||||
TestPlugin::~TestPlugin()
|
||||
{
|
||||
if (m_widget) {
|
||||
delete m_widget;
|
||||
m_widget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const QString TestPlugin::pluginName() const
|
||||
{
|
||||
return QString(Name);
|
||||
@ -24,7 +33,7 @@ void TestPlugin::init(PluginProxyInterface *)
|
||||
|
||||
QWidget *TestPlugin::itemWidget(const QString &)
|
||||
{
|
||||
return new QWidget;
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
int TestPlugin::itemSortKey(const QString &)
|
||||
|
@ -3,12 +3,15 @@
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
|
||||
#include <QPointer>
|
||||
const QString Name = "Test";
|
||||
|
||||
class QWidget;
|
||||
class TestPlugin : public PluginsItemInterface
|
||||
{
|
||||
public:
|
||||
TestPlugin();
|
||||
~ TestPlugin() override;
|
||||
|
||||
virtual const QString pluginName() const override;
|
||||
virtual const QString pluginDisplayName() const override;
|
||||
@ -25,6 +28,7 @@ public:
|
||||
private:
|
||||
int m_sortKey;
|
||||
PluginType m_type;
|
||||
QPointer<QWidget> m_widget;
|
||||
};
|
||||
|
||||
#endif // TESTPLUGIN_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user