Skip to content

Commit

Permalink
Don't test before deleting a pointer
Browse files Browse the repository at this point in the history
It's fine to delete a null pointer. It has no effect.
Assign nullptr after deleting make an access violation visible (crash).
  • Loading branch information
luis-pereira authored and yan12125 committed Jan 19, 2024
1 parent 69f6bbc commit 8064fdb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/bookmarkswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ BookmarksModel::BookmarksModel(QObject *parent)

void BookmarksModel::setup()
{
if (m_root)
delete m_root;
delete m_root;
m_root = new BookmarkRootItem();
m_root->addChild(new BookmarkFileGroupItem(m_root, Properties::Instance()->bookmarksFile));
beginResetModel();
Expand All @@ -203,8 +202,8 @@ void BookmarksModel::setup()

BookmarksModel::~BookmarksModel()
{
if (m_root)
delete m_root;
delete m_root;
m_root = nullptr;
}

int BookmarksModel::columnCount(const QModelIndex & /* parent */) const
Expand Down

0 comments on commit 8064fdb

Please sign in to comment.