Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Add_Entry #1095

Open
xezon opened this issue Feb 8, 2024 · 0 comments
Open

Memory leak in Add_Entry #1095

xezon opened this issue Feb 8, 2024 · 0 comments
Labels
investigate Investigation and careful discussion needed vanilla-bug

Comments

@xezon
Copy link
Contributor

xezon commented Feb 8, 2024

int Move_Rows_Down(_ListboxData *data, int row)
{
    int size = sizeof(_ListEntryRow) * (data->m_endPos - row);
    char *buf = new char[size];
    memcpy(buf, &data->m_listData[row], size);
    memcpy(&data->m_listData[row + 1], buf, size);
    delete[] buf;
    data->m_insertPos = ++data->m_endPos;
    data->m_listData[row].m_cell = 0;
    data->m_listData[row].m_height = 0;
    data->m_listData[row].m_listHeight = 0;

    if (data->m_multiSelect) {
        for (int i = 0; data->m_selections[i] >= 0; i++) {
            if (row <= data->m_selections[i]) {
                data->m_selections[i]++;
            }
        }
    } else if (data->m_selectPos >= row) {
        data->m_selectPos++;
    }

    return 1;
}

int Add_Entry(Utf16String *string, int color, int row, int column, GameWindow *list_box, bool overwrite)
{
...
        _ListEntryRow *list_row = &data->m_listData[row];

        if (list_row->m_cell != nullptr) {
            if (!overwrite) {
                Move_Rows_Down(data, row);
                list_row->m_cell = new _ListEntryCell[data->m_columns];
                memset(list_row->m_cell, 0, sizeof(_ListEntryCell) * data->m_columns);
                adjust = 1;
            }

Add_Entry does list_row->m_cell = new _ListEntryCell[data->m_columns];. There are no deletes prior, so this looks like memory leak at this point.

@xezon xezon added vanilla-bug investigate Investigation and careful discussion needed labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Investigation and careful discussion needed vanilla-bug
Projects
None yet
Development

No branches or pull requests

1 participant