weimingtom / angel-engine

Automatically exported from code.google.com/p/angel-engine
0 stars 0 forks source link

OpenAL returns pointer to temporary #91

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In SoundDevice.cpp

    const char * OpenAL_ErrorString(ALenum errCode)
    {
        String retVal;
                // unrelated body
        return retVal.c_str();
    }

c_str() returns a pointer to the buffer String owns.
But retVal goes out of scope after the return. 

The return value of this function is a pointer to a buffer that is almost 
certainly now free'd. It works, because that memory isn't zero'd out, and it's 
quite likely that it isn't collected by the OS quickly enough for it to be 
gone, but it's definitely not correct.

Instead, this function should return a String, and that String should have 
.c_str() called on it; due to RVO and rvalue semantics, this shouldn't be any 
slower.

Original issue reported on code.google.com by LoveOver...@gmail.com on 10 Apr 2014 at 6:01