Skip to content

Removed GLFW leaks #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2023
Merged

Removed GLFW leaks #112

merged 1 commit into from
Jun 12, 2023

Conversation

XEDGit
Copy link
Contributor

@XEDGit XEDGit commented Jun 8, 2023

Leaks list
mlx_init.c:

  • 84: glCreateShader(type)
    The shader was not being deleted correctly, it has to be detached
    before being deleted, the documentation says you only need to use
    glDeleteProgram and they'll be detached but from my tests it is
    not true

  • 120: glCreateProgram()
    The shader program wasn't being deleted at all with glDeleteProgram

  • 124: glLinkProgram(mlxctx->shaderprogram)
    I have very hard time understanding the underlaying system, the docs
    don't make any reference to it, but calling again glLinkProgram
    before deleting shaderprogram frees the leaks generated from the first call

  • 88: glShaderSource(shader, 1, &code, &len)
    I figued out the leak consists in the copy of the code allocated for the shader
    but I could't understand how to free it, apparently glDeleteShader doesn't take
    care of it
    New mlx_terminate with modifications:

void mlx_terminate(mlx_t* mlx)
{
	MLX_NONNULL(mlx);
	mlx_ctx_t *const mlxctx = mlx->context;
	// to add for leaks
	glUseProgram(0);	// removes shaderprogram from context
	glLinkProgram(mlxctx->shaderprogram); // frees memory allocated earlier by same function
	glDeleteProgram(mlxctx->shaderprogram); // deletes shaderprogram
	// end
	glfwTerminate();
	mlx_lstclear((mlx_list_t**)(&mlxctx->hooks), &free);
	mlx_lstclear((mlx_list_t**)(&mlxctx->render_queue), &free);
	mlx_lstclear((mlx_list_t**)(&mlxctx->images), &mlx_free_image);
	mlx_freen(2, mlxctx, mlx);
}
mlx_init_renderer, add these lines after deleting the shader:
glDetachShader(mlxctx->shaderprogram, vshader);
glDetachShader(mlxctx->shaderprogram, fshader);

@W2Wizard W2Wizard added the Fix Fixed or resolved an issue label Jun 8, 2023
Copy link
Collaborator

@W2Wizard W2Wizard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit to me, I was under the impression that mostly delete should take care of it but I guess I was wrong?

@W2Wizard W2Wizard merged commit 614265d into codam-coding-college:master Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Fixed or resolved an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants