From 1a3fe41b1eb18ab5926438f7979c7a4f3a6b1fb6 Mon Sep 17 00:00:00 2001 From: lieff Date: Fri, 18 May 2018 00:10:08 +0300 Subject: [PATCH] fix error handling --- src/nanovg.c | 7 ++++++- src/nanovg_gl.h | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nanovg.c b/src/nanovg.c index aab410df..fb448227 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -288,7 +288,12 @@ NVGcontext* nvgCreateInternal(NVGparams* params) FONSparams fontParams; NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext)); int i; - if (ctx == NULL) goto error; + 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; + } memset(ctx, 0, sizeof(NVGcontext)); ctx->params = *params; diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 30854ca2..b89eba91 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -1589,8 +1589,6 @@ NVGcontext* nvgCreateGLES3(int flags) return ctx; error: - // 'gl' is freed by nvgDeleteInternal. - if (ctx != NULL) nvgDeleteInternal(ctx); return NULL; }