Merge pull request #11578 from Pokechu22/memory-leaks-feb-2023

Fix various memory leaks
This commit is contained in:
Admiral H. Curtiss 2023-02-18 13:56:34 +01:00 committed by GitHub
commit 8db35e6d04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 18 deletions

View File

@ -51,7 +51,7 @@ constexpr u32 WIDTH_PER_BRANCH_ARROW = 16;
class BranchDisplayDelegate : public QStyledItemDelegate class BranchDisplayDelegate : public QStyledItemDelegate
{ {
public: public:
BranchDisplayDelegate(CodeViewWidget* parent) : m_parent(parent) {} BranchDisplayDelegate(CodeViewWidget* parent) : QStyledItemDelegate(parent), m_parent(parent) {}
private: private:
CodeViewWidget* m_parent; CodeViewWidget* m_parent;

View File

@ -321,36 +321,36 @@ void MemoryViewWidget::CreateTable()
// Create cells and add data that won't be changing. // Create cells and add data that won't be changing.
// Breakpoint buttons // Breakpoint buttons
auto* bp_item = new QTableWidgetItem; auto bp_item = QTableWidgetItem();
bp_item->setFlags(Qt::ItemIsEnabled); bp_item.setFlags(Qt::ItemIsEnabled);
bp_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, true); bp_item.setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, true);
bp_item->setData(USER_ROLE_VALUE_TYPE, static_cast<int>(Type::Null)); bp_item.setData(USER_ROLE_VALUE_TYPE, static_cast<int>(Type::Null));
// Row Addresses // Row Addresses
auto* row_item = new QTableWidgetItem(INVALID_MEMORY); auto row_item = QTableWidgetItem(INVALID_MEMORY);
row_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); row_item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
row_item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false); row_item.setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
row_item->setData(USER_ROLE_VALUE_TYPE, static_cast<int>(Type::Null)); row_item.setData(USER_ROLE_VALUE_TYPE, static_cast<int>(Type::Null));
// Data item // Data item
auto* item = new QTableWidgetItem(INVALID_MEMORY); auto item = QTableWidgetItem(INVALID_MEMORY);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
item->setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false); item.setData(USER_ROLE_IS_ROW_BREAKPOINT_CELL, false);
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
m_table->setItem(i, 0, bp_item->clone()); m_table->setItem(i, 0, bp_item.clone());
m_table->setItem(i, 1, row_item->clone()); m_table->setItem(i, 1, row_item.clone());
for (int c = 0; c < m_data_columns; c++) for (int c = 0; c < m_data_columns; c++)
{ {
if (left_type && c < data_span) if (left_type && c < data_span)
{ {
item->setData(USER_ROLE_VALUE_TYPE, static_cast<int>(left_type.value())); item.setData(USER_ROLE_VALUE_TYPE, static_cast<int>(left_type.value()));
} }
else else
{ {
item->setData(USER_ROLE_VALUE_TYPE, static_cast<int>(m_type)); item.setData(USER_ROLE_VALUE_TYPE, static_cast<int>(m_type));
// Left type will never be these. // Left type will never be these.
auto text_alignment = Qt::AlignLeft; auto text_alignment = Qt::AlignLeft;
@ -359,10 +359,10 @@ void MemoryViewWidget::CreateTable()
{ {
text_alignment = Qt::AlignRight; text_alignment = Qt::AlignRight;
} }
item->setTextAlignment(text_alignment | Qt::AlignVCenter); item.setTextAlignment(text_alignment | Qt::AlignVCenter);
} }
m_table->setItem(i, c + MISC_COLUMNS, item->clone()); m_table->setItem(i, c + MISC_COLUMNS, item.clone());
} }
} }

View File

@ -37,6 +37,7 @@ public:
void operator()(T* func) void operator()(T* func)
{ {
(*func)(); (*func)();
delete func;
} }
}; };