From 2de6a8b665eda6ac50fe4c507e57e95315a0912b Mon Sep 17 00:00:00 2001 From: kartofen Date: Mon, 16 Oct 2023 23:54:54 +0300 Subject: fix memory leak and code clarity --- src/main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 90985be..376e137 100644 --- a/src/main.c +++ b/src/main.c @@ -40,21 +40,16 @@ int main(void) unsigned int ext_count = 0; window_extension_info(window, &ext_count, NULL); + char **extensions = xcalloc(ext_count, sizeof(char *)); + window_extension_info(window, &ext_count, (const char **)extensions); + // populate the device info struct device_info dev_info = {0}; dev_info.name = "Test App"; dev_info.version = MAKE_VERSION(1, 0, 0); - if(ext_count == 0){ - dev_info.ext_count = 0; - dev_info.extensions = NULL; - } else { - char **extensions = xcalloc(ext_count, sizeof(char *)); - window_extension_info(window, &ext_count, (const char **)extensions); - - dev_info.ext_count = ext_count; - dev_info.extensions = (const char * const *)extensions; - } + dev_info.ext_count = ext_count; + dev_info.extensions = (const char * const *)extensions; dev_info.surface_func = _create_surface; @@ -64,6 +59,8 @@ int main(void) err("device_create: failed"); goto df; } + + if(extensions) free(extensions); int running = 1; while(running) { -- cgit v1.2.3