Skip to content

Commit 6c8b330

Browse files
committed
Limit table buffer to avoid memory allocation issue for large buffers
1 parent a9f956a commit 6c8b330

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

qt/buffer_table_model.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "buffer_table_model.h"
77

8+
#define TABLE_BUFFER_LIMIT (1024*1024*1024)
9+
810
BufferTableModel::BufferTableModel(QObject *parent):
911
QAbstractTableModel(parent)
1012
{
@@ -14,7 +16,13 @@ BufferTableModel::BufferTableModel(QObject *parent):
1416

1517
int BufferTableModel::rowCount(const QModelIndex & /*parent*/) const
1618
{
17-
return (state.fileSize + ROW_DATA_SIZE - 1) / ROW_DATA_SIZE;
19+
qint64 tableBufferSize = state.fileSize;
20+
21+
// Limit buffer size to avoid memory overlows for large buffers
22+
if (tableBufferSize > TABLE_BUFFER_LIMIT)
23+
tableBufferSize = TABLE_BUFFER_LIMIT;
24+
25+
return (tableBufferSize + ROW_DATA_SIZE - 1) / ROW_DATA_SIZE;
1826
}
1927

2028
int BufferTableModel::columnCount(const QModelIndex & /*parent*/) const

0 commit comments

Comments
 (0)