Skip to content

fix error handling#481

Open
lieff wants to merge 1 commit intomemononen:masterfrom
lieff:master
Open

fix error handling#481
lieff wants to merge 1 commit intomemononen:masterfrom
lieff:master

Conversation

@lieff
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/nanovg.c
NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext));
int i;
if (ctx == NULL) goto error;
if (ctx == NULL) {
Copy link
Copy Markdown
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;
}

Comment thread src/nanovg_gl.h Outdated
@@ -1590,7 +1590,6 @@ NVGcontext* nvgCreateGLES3(int flags)

error:
// 'gl' is freed by nvgDeleteInternal.
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

lieff commented May 17, 2018

Updated)

@lieff
Copy link
Copy Markdown
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