gluQuadric Functions & Memory Leaks

The snippet of code below appears in another post on the forum.
As used below, would the glu functions result in a memory leak?
Would declaring qobj to be ‘static’ be a workaround?
Thanks.


void drawcannon()
{
	glLoadIdentity();
	glColor3f(1.0, 0.0, 0.0);
	qobj = gluNewQuadric();
	gluQuadricNormals(qobj, GLU_SMOOTH);
	gluCylinder(qobj, 1.0, 1.0, 0.4, 10, 16);
        ......
}

[QUOTE=Carmine;1280195]The snippet of code below appears in another post on the forum.
As used below, would the glu functions result in a memory leak?
[/QUOTE]
Yes. In this case, the quadric object should be deleted with gluDeleteQuadric(). Alternatively …

The same quadric could be used for the lifetime of the program, with the pointer stored in a global variable or “static” local variable. E.g.


	static GLUquadric *qobj;

	if (!qobj) {
		qobj = gluNewQuadric();
		gluQuadricNormals(qobj, GLU_SMOOTH);
	}

	gluCylinder(qobj, 1.0, 1.0, 0.4, 10, 16);