From 2f43ec3d764d2f4d51ab22ceb408557695f86e43 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 23 Jun 2022 17:05:23 +0200 Subject: [PATCH] GL disp.: small fixes - try-catch state_gl constructor (now it can throw) - added a explaining comment --- src/video_display/gl.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index 85013d104..844508423 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -665,7 +665,12 @@ static void *display_gl_parse_fmt(struct state_gl *s, char *ptr) { static void * display_gl_init(struct module *parent, const char *fmt, unsigned int flags) { UNUSED(flags); - struct state_gl *s = new state_gl(parent); + struct state_gl *s = nullptr; + try { + s = new state_gl(parent); + } catch (...) { + return nullptr; + } if (fmt != NULL) { char *tmp = strdup(fmt); @@ -676,7 +681,7 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i LOG(LOG_LEVEL_ERROR) << MOD_NAME << "Invalid numeric value for an option!\n"; } free(tmp); - if (ret != s) { + if (ret != s) { // ret is either nullptr or &display_init_noerr (help requested) delete s; return ret; }