Yes it's bad. It's a memory leak because the allocated array is never deleted (as you said).
Here's a version that doesn't leak
GLfloat VertexArray(Vertex<GLfloat> v1, Vertex<GLfloat> v2, Vertex<GLfloat> v3) {
return v1.x;
};
No allocation is needed for the function you wrote, because the only value you are returning is the first in your array which is v1.x
.
Now this is a rather pointless function, so maybe your real code is more complicated than the code you posted.
Maybe you meant to write a function that returns the whole array. In that case return the pointer that you allocated return ArrayPtr;
. In that case you still need to delete the pointer, but you can do it somewhere in the code that called this function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…