Browse Source

Remove redundant null checks

Attempting to delete a null pointer is a noop in C++.

Closes #2864.

[1] https://isocpp.org/wiki/faq/freestore-mgmt#delete-handles-null
adaptive-webui-19844
NotTsunami 5 years ago
parent
commit
6748e8d787
  1. 4
      src/base/bittorrent/session.cpp
  2. 2
      src/base/iconprovider.cpp
  3. 2
      src/base/logger.cpp
  4. 2
      src/base/net/downloadmanager.cpp
  5. 8
      src/base/net/geoipmanager.cpp
  6. 1
      src/base/net/private/downloadhandlerimpl.cpp
  7. 2
      src/base/net/proxyconfigurationmanager.cpp
  8. 2
      src/base/preferences.cpp
  9. 2
      src/base/scanfoldersmodel.cpp
  10. 1
      src/base/search/searchpluginmanager.cpp
  11. 7
      src/gui/mainwindow.cpp
  12. 2
      src/gui/private/fspathedit_p.cpp
  13. 2
      src/gui/uithememanager.cpp
  14. 6
      src/webui/webui.cpp

4
src/base/bittorrent/session.cpp

@ -977,7 +977,6 @@ Session::~Session() @@ -977,7 +977,6 @@ Session::~Session()
// We must delete FilterParserThread
// before we delete lt::session
if (m_filterParser)
delete m_filterParser;
// We must delete PortForwarderImpl before
@ -1002,10 +1001,8 @@ void Session::initInstance() @@ -1002,10 +1001,8 @@ void Session::initInstance()
void Session::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
Session *Session::instance()
@ -1605,7 +1602,6 @@ void Session::enableTracker(const bool enable) @@ -1605,7 +1602,6 @@ void Session::enableTracker(const bool enable)
m_tracker->start();
}
else {
if (m_tracker)
delete m_tracker;
}
}

2
src/base/iconprovider.cpp

@ -46,10 +46,8 @@ void IconProvider::initInstance() @@ -46,10 +46,8 @@ void IconProvider::initInstance()
void IconProvider::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
IconProvider *IconProvider::instance()

2
src/base/logger.cpp

@ -65,10 +65,8 @@ void Logger::initInstance() @@ -65,10 +65,8 @@ void Logger::initInstance()
void Logger::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
void Logger::addMessage(const QString &message, const Log::MsgType &type)

2
src/base/net/downloadmanager.cpp

@ -152,10 +152,8 @@ void Net::DownloadManager::initInstance() @@ -152,10 +152,8 @@ void Net::DownloadManager::initInstance()
void Net::DownloadManager::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
Net::DownloadManager *Net::DownloadManager::instance()

8
src/base/net/geoipmanager.cpp

@ -63,7 +63,6 @@ GeoIPManager::GeoIPManager() @@ -63,7 +63,6 @@ GeoIPManager::GeoIPManager()
GeoIPManager::~GeoIPManager()
{
if (m_geoIPDatabase)
delete m_geoIPDatabase;
}
@ -75,10 +74,8 @@ void GeoIPManager::initInstance() @@ -75,10 +74,8 @@ void GeoIPManager::initInstance()
void GeoIPManager::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
GeoIPManager *GeoIPManager::instance()
@ -88,10 +85,8 @@ GeoIPManager *GeoIPManager::instance() @@ -88,10 +85,8 @@ GeoIPManager *GeoIPManager::instance()
void GeoIPManager::loadDatabase()
{
if (m_geoIPDatabase) {
delete m_geoIPDatabase;
m_geoIPDatabase = nullptr;
}
const QString filepath = Utils::Fs::expandPathAbs(
QString("%1%2/%3").arg(specialFolderLocation(SpecialFolder::Data), GEOIP_FOLDER, GEOIP_FILENAME));
@ -398,7 +393,7 @@ void GeoIPManager::configure() @@ -398,7 +393,7 @@ void GeoIPManager::configure()
if (m_enabled && !m_geoIPDatabase) {
loadDatabase();
}
else if (!m_enabled && m_geoIPDatabase) {
else if (!m_enabled) {
delete m_geoIPDatabase;
m_geoIPDatabase = nullptr;
}
@ -423,7 +418,6 @@ void GeoIPManager::downloadFinished(const DownloadResult &result) @@ -423,7 +418,6 @@ void GeoIPManager::downloadFinished(const DownloadResult &result)
GeoIPDatabase *geoIPDatabase = GeoIPDatabase::load(data, error);
if (geoIPDatabase) {
if (!m_geoIPDatabase || (geoIPDatabase->buildEpoch() > m_geoIPDatabase->buildEpoch())) {
if (m_geoIPDatabase)
delete m_geoIPDatabase;
m_geoIPDatabase = geoIPDatabase;
LogMsg(tr("GeoIP database loaded. Type: %1. Build time: %2.")

1
src/base/net/private/downloadhandlerimpl.cpp

@ -63,7 +63,6 @@ DownloadHandlerImpl::DownloadHandlerImpl(const Net::DownloadRequest &downloadReq @@ -63,7 +63,6 @@ DownloadHandlerImpl::DownloadHandlerImpl(const Net::DownloadRequest &downloadReq
DownloadHandlerImpl::~DownloadHandlerImpl()
{
if (m_reply)
delete m_reply;
}

2
src/base/net/proxyconfigurationmanager.cpp

@ -84,10 +84,8 @@ void ProxyConfigurationManager::initInstance() @@ -84,10 +84,8 @@ void ProxyConfigurationManager::initInstance()
void ProxyConfigurationManager::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
ProxyConfigurationManager *ProxyConfigurationManager::instance()

2
src/base/preferences.cpp

@ -77,10 +77,8 @@ void Preferences::initInstance() @@ -77,10 +77,8 @@ void Preferences::initInstance()
void Preferences::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
const QVariant Preferences::value(const QString &key, const QVariant &defaultValue) const

2
src/base/scanfoldersmodel.cpp

@ -69,10 +69,8 @@ bool ScanFoldersModel::initInstance(QObject *parent) @@ -69,10 +69,8 @@ bool ScanFoldersModel::initInstance(QObject *parent)
void ScanFoldersModel::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
ScanFoldersModel *ScanFoldersModel::instance()

1
src/base/search/searchpluginmanager.cpp

@ -104,7 +104,6 @@ SearchPluginManager *SearchPluginManager::instance() @@ -104,7 +104,6 @@ SearchPluginManager *SearchPluginManager::instance()
void SearchPluginManager::freeInstance()
{
if (m_instance)
delete m_instance;
}

7
src/gui/mainwindow.cpp

@ -678,7 +678,7 @@ void MainWindow::displayRSSTab(bool enable) @@ -678,7 +678,7 @@ void MainWindow::displayRSSTab(bool enable)
#endif
}
}
else if (m_rssWidget) {
else {
delete m_rssWidget;
}
}
@ -714,7 +714,7 @@ void MainWindow::displaySearchTab(bool enable) @@ -714,7 +714,7 @@ void MainWindow::displaySearchTab(bool enable)
tr("Search"));
}
}
else if (m_searchWidget) {
else {
delete m_searchWidget;
}
}
@ -1170,7 +1170,6 @@ void MainWindow::closeEvent(QCloseEvent *e) @@ -1170,7 +1170,6 @@ void MainWindow::closeEvent(QCloseEvent *e)
}
// abort search if any
if (m_searchWidget)
delete m_searchWidget;
hide();
@ -1875,7 +1874,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked) @@ -1875,7 +1874,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
m_tabs->setTabIcon(indexTab, UIThemeManager::instance()->getIcon("view-calendar-journal"));
#endif
}
else if (m_executionLog) {
else {
delete m_executionLog;
}

2
src/gui/private/fspathedit_p.cpp

@ -259,11 +259,9 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e) @@ -259,11 +259,9 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e)
FileSystemPathValidator::TestResult lastTestResult = validator->lastTestResult();
QValidator::State lastState = validator->lastValidationState();
if (lastTestResult == FileSystemPathValidator::TestResult::OK) {
if (m_warningAction) {
delete m_warningAction;
m_warningAction = nullptr;
}
}
else {
if (!m_warningAction) {
m_warningAction = new QAction(this);

2
src/gui/uithememanager.cpp

@ -43,10 +43,8 @@ UIThemeManager *UIThemeManager::m_instance = nullptr; @@ -43,10 +43,8 @@ UIThemeManager *UIThemeManager::m_instance = nullptr;
void UIThemeManager::freeInstance()
{
if (m_instance) {
delete m_instance;
m_instance = nullptr;
}
}
void UIThemeManager::initInstance()

6
src/webui/webui.cpp

@ -127,20 +127,14 @@ void WebUI::configure() @@ -127,20 +127,14 @@ void WebUI::configure()
m_dnsUpdater->updateCredentials();
}
else {
if (m_dnsUpdater)
delete m_dnsUpdater;
}
}
else {
Net::PortForwarder::instance()->deletePort(oldPort);
if (m_httpServer)
delete m_httpServer;
if (m_webapp)
delete m_webapp;
if (m_dnsUpdater)
delete m_dnsUpdater;
}
}

Loading…
Cancel
Save