Skip to content

Conversation

@lieff
Copy link
Contributor

@lieff lieff commented May 17, 2018

ctx can't be != NULL on error path, nvgDeleteInternal can return immediately (if (ctx == NULL) return;) without userPtr cleanup => "gl" can leak.

Copy link
Owner

@memononen memononen left a comment

Choose a reason for hiding this comment

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

Good catch! A couple of fixed still needed, though.

NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext));
int i;
if (ctx == NULL) goto error;
if (ctx == NULL) {
Copy link
Owner

Choose a reason for hiding this comment

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

This should be (ctx->params is not set yet either):

if (ctx == NULL) {
	// Call renderer delete explicitly. Context is not initialized yet, so we cannot call nvgDeleteInternal() which usually calls the function.
	if (params->renderDelete != NULL)
		params->renderDelete(params->userPtr);
	return  NULL;
}

src/nanovg_gl.h Outdated
return ctx;

error:
// 'gl' is freed by nvgDeleteInternal.
Copy link
Owner

Choose a reason for hiding this comment

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

remove comment

@lieff
Copy link
Contributor Author

lieff commented May 17, 2018

Updated)

@lieff
Copy link
Contributor Author

lieff commented May 30, 2018

Is changes good? Anything needed from my side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants