diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index 540c3108f..830727487 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -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") diff --git a/frame/util/themeappicon.cpp b/frame/util/themeappicon.cpp index 03c244442..e92b7ce4e 100644 --- a/frame/util/themeappicon.cpp +++ b/frame/util/themeappicon.cpp @@ -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); } diff --git a/plugins/tray/snitraywidget.cpp b/plugins/tray/snitraywidget.cpp index de6afa53b..99530cd8c 100644 --- a/plugins/tray/snitraywidget.cpp +++ b/plugins/tray/snitraywidget.cpp @@ -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; diff --git a/plugins/tray/snitraywidget.h b/plugins/tray/snitraywidget.h index 0ac881742..993bce9ff 100644 --- a/plugins/tray/snitraywidget.h +++ b/plugins/tray/snitraywidget.h @@ -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; diff --git a/plugins/tray/xembedtraywidget.cpp b/plugins/tray/xembedtraywidget.cpp index d1da0e480..8407c3d6a 100644 --- a/plugins/tray/xembedtraywidget.cpp +++ b/plugins/tray/xembedtraywidget.cpp @@ -183,11 +183,12 @@ void XEmbedTrayWidget::wrapWindow() } auto cookie = xcb_get_geometry(c, m_windowId); - QScopedPointer 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 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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5026d2a49..bbe7463d0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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") diff --git a/tests/item/components/ut_appdrag.cpp b/tests/item/components/ut_appdrag.cpp index cc886b7e8..8513d1e82 100644 --- a/tests/item/components/ut_appdrag.cpp +++ b/tests/item/components/ut_appdrag.cpp @@ -51,6 +51,6 @@ TEST_F(Test_AppDrag, drag_test) drag->exec(); - delete drag; - drag = nullptr; + delete w; + w = nullptr; } diff --git a/tests/item/components/ut_floatingpreview.cpp b/tests/item/components/ut_floatingpreview.cpp index f221517dc..5d7376acf 100644 --- a/tests/item/components/ut_floatingpreview.cpp +++ b/tests/item/components/ut_floatingpreview.cpp @@ -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; } diff --git a/tests/item/testplugin.cpp b/tests/item/testplugin.cpp index 08fd113da..b09da9946 100644 --- a/tests/item/testplugin.cpp +++ b/tests/item/testplugin.cpp @@ -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 &) diff --git a/tests/item/testplugin.h b/tests/item/testplugin.h index 8fa381922..0dfc3eb7f 100644 --- a/tests/item/testplugin.h +++ b/tests/item/testplugin.h @@ -3,12 +3,15 @@ #include "pluginsiteminterface.h" +#include 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 m_widget; }; #endif // TESTPLUGIN_H