StanEpp / OpenGL_ParticleSystem

MIT License
128 stars 33 forks source link

This code will leak and does an unnecessary allocation #2

Closed AlexEne closed 10 years ago

AlexEne commented 10 years ago

From ShaderManager.cpp:

GLsizei* length = new GLsizei; //new is not needed. just GLsizei length = 0; is ok then you just pass it's address in the function below It's not an array. It's just a value. You can use it like this: glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &length); char* compilationLog = new char[length];
glGetShaderInfoLog(shaderID, length, NULL, compilationLog);

throw std::exception(([...]+std::string(compilationLog)).c_str()); //Throwing here means you never deallocate compilationLog ( and never deallocate "length" from the original code )

StanEpp commented 10 years ago

Thanks! I fixed the issues =)

AlexEne commented 10 years ago

You made a small mistake here:

char* compilationLog = new char[length]; [...] delete compilationLog;

This should be delete[] since it was allocated with was new [].

StanEpp commented 10 years ago

Oww... You're right. Thanks! =)