ValveSoftware / source-sdk-2013

The 2013 edition of the Source SDK
https://developer.valvesoftware.com/wiki/SDK2013_GettingStarted
Other
3.8k stars 2k forks source link

Incorrect delete call in mathlib quantize.cpp #319

Open SizzlingCalamari opened 9 years ago

SizzlingCalamari commented 9 years ago

In the alloc/free pair AllocQValue and FreeQuantization in quantize.cpp, a call to new is using an incorrect corresponding call to delete.

static struct QuantizedValue *AllocQValue(void)
{
    struct QuantizedValue *ret=new QuantizedValue;
    ...
}

void FreeQuantization(struct QuantizedValue *t)
{
    if (t)
    {
        ...
        delete[] t;
    }
}

The delete call should be delete t;

bmk10 commented 9 years ago

guessing this may cause , a memory leak, its probably not the only one, and I don't want to find out how it effects mac/linux/windows differently

SizzlingCalamari commented 9 years ago

@bmk10 It's up to the implementation, but if it doesn't crash, I'd assume it has no adverse effects. It's just incorrect according to the language.

AltimorTASDK commented 9 years ago

QuantizedValue has no destructor, so this won't cause any errors. If it ever had one added I'm guessing this would crash, or worse, corrupt memory and keep running.