Skip to content

Commit cad71fb

Browse files
committed
Fixed free of read buffer
1 parent a7a5ef7 commit cad71fb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

qt/main_window.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void MainWindow::resetBufTable()
4444
{
4545
bufferTableModel.setBuffer(nullptr, 0);
4646
bufferSize = 0;
47-
delete buffer;
47+
delete [] buffer;
4848
}
4949

5050
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
@@ -89,7 +89,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
8989

9090
MainWindow::~MainWindow()
9191
{
92-
delete buffer;
92+
delete [] buffer;
9393
Logger::putInstance();
9494
delete ui;
9595
}
@@ -276,7 +276,7 @@ void MainWindow::slotProgReadCompleted(int status)
276276

277277
if (status)
278278
{
279-
delete buffer;
279+
delete [] buffer;
280280
return;
281281
}
282282

@@ -288,10 +288,13 @@ void MainWindow::slotProgRead()
288288
{
289289
int index = ui->chipSelectComboBox->currentIndex();
290290
ChipInfo *chipInfo = chipDb.chipInfoGetById(CHIP_INDEX2ID(index));
291-
uint32_t readSize = chipInfo->params[CHIP_PARAM_BLOCK_SIZE];
291+
uint32_t readSize = chipInfo->params[CHIP_PARAM_SIZE];
292292

293-
connect(prog, SIGNAL(readChipCompleted(int)), this,
294-
SLOT(slotProgReadCompleted(int)));
293+
if (!readSize)
294+
{
295+
qCritical() << "Chip size is not set";
296+
return;
297+
}
295298

296299
resetBufTable();
297300
buffer = new (std::nothrow) uint8_t[readSize];
@@ -301,6 +304,9 @@ void MainWindow::slotProgRead()
301304
return;
302305
}
303306

307+
connect(prog, SIGNAL(readChipCompleted(int)), this,
308+
SLOT(slotProgReadCompleted(int)));
309+
304310
prog->readChip(buffer, START_ADDRESS, readSize, true);
305311
}
306312

0 commit comments

Comments
 (0)