Skip to main content
New Participant
February 5, 2016

Bug Report: Memory leak in Win32_DirectXAppUtil.h

Hi, not sure where the right place to put this is, but I noticed that there's a memory leak in one of the headers included in all the 0.8 SDK Samples. See the following code (pix isn't been free'd):


Win32_DirectXAppUtil.h ln 438
void AutoFillTexture(int autoFillData)
{
DWORD * pix = (DWORD *)malloc(sizeof(DWORD) * SizeW * SizeH);
for (int j = 0; j < SizeH; j++)
for (int i = 0; i < SizeW; i++)
{
DWORD * curr = &pix[j*SizeW + i];
switch (autoFillData)
{
case(AUTO_WALL) : *curr = (((j / 4 & 15) == 0) || (((i / 4 & 15) == 0) && ((((i / 4 & 31) == 0) ^ ((j / 4 >> 4) & 1)) == 0))) ?
0xff3c3c3c : 0xffb4b4b4; break;
case(AUTO_FLOOR) : *curr = (((i >> 7) ^ (j >> 7)) & 1) ? 0xffb4b4b4 : 0xff505050; break;
case(AUTO_CEILING) : *curr = (i / 4 == 0 || j / 4 == 0) ? 0xff505050 : 0xffb4b4b4; break;
case(AUTO_WHITE) : *curr = 0xffffffff; break;
case(AUTO_GRADE_256) : *curr = 0xff000000 + i * 0x010101; break;
case(AUTO_GRID) : *curr = (i<4) || (i>(SizeW - 5)) || (j<4) || (j>(SizeH - 5)) ? 0xffffffff : 0xff000000; break;
default: *curr = 0xffffffff; break;
}
///ConvertToSRGB(curr); //Require format for SDK - I've been recommended to remove for now.
}
FillTexture(pix);
free(pix); // This isnt here in the SDK, which causes "pix" to be leaked.
}


Just thought I'd let you know (is there a better place for this kind of thing?).

    2 replies

    Up and Coming
    February 5, 2016
    Never raw pointer !

    auto pix = std::make_unique<dword[]>(w*h);
    Inspiring
    February 5, 2016
    Let me see if anyone knows about this.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV