HEAP CORRUPTION DETECTED BUG

Viewed 36

I was creating a jagged array. However,

#include <iostream>

#include "Array.h"

int main()
{
    tArr s1 = {};

    Init(&s1);


    for (int i = 0; i < 10; ++i)
    {`enter code here`
        PushBack(&s1, i);
    }


    Release(&s1);

    return 0;
}

while implementing and executing the release function, an error occurred in the release function implementation part.

void Release(tArr* _pArr)
{
    free(_pArr->Pint);
    _pArr->Icount = 0;
    _pArr->Icountmax = 0;
}

In the above syntax, _pArr->Icount = 0; in part,

HEAP CORRUPTION DETECTED: after Normal block (#74) at 0x0000028520E7D280. CRT detected the the application wrote to memory after end of heap buffer.

The following error occurred:

please tell me....PLEASE...AJ;DSFPASOF

This is the full code.

#include "Array.h"

#include <iostream>

void Init(tArr* _pArr)
{
    _pArr->Pint = (int*)malloc(sizeof(int) * 2);
    _pArr->Icount = 0;
    _pArr->Icountmax = 2;
}

void Reallocate(tArr* _pArr)
{
    // 1. 
    int* pNew = (int*)malloc(_pArr->Icountmax * 2 * sizeof(int));
}

void PushBack(tArr* _pArr, int _iData)
{
    // 힙 영역에 할당한 공간이 다 참
    if (_pArr->Icount <= _pArr->Icountmax)
    {
        Reallocate(_pArr);
    }

    // 데이터 추가
    _pArr->Pint[_pArr->Icount++] = _iData;
}

void Release(tArr* _pArr)
{
    free(_pArr->Pint);
    _pArr->Icount = 0;
    _pArr->Icountmax = 0;
}
0 Answers
Related