diff options
| author | kartofen <mladenovnasko0@gmail.com> | 2023-10-16 23:54:54 +0300 | 
|---|---|---|
| committer | kartofen <mladenovnasko0@gmail.com> | 2023-10-16 23:54:54 +0300 | 
| commit | 2de6a8b665eda6ac50fe4c507e57e95315a0912b (patch) | |
| tree | e982725c0d1d79bca2be3c20363a30763e8dcd38 | |
| parent | 5e910c7e41d18dab95e34ceb6e620a8958197ae6 (diff) | |
fix memory leak and code clarity
| -rw-r--r-- | src/device.c | 2 | ||||
| -rw-r--r-- | src/main.c | 17 | 
2 files changed, 7 insertions, 12 deletions
| diff --git a/src/device.c b/src/device.c index fdcc7ad..d899062 100644 --- a/src/device.c +++ b/src/device.c @@ -128,8 +128,6 @@ static int create_instance(device_t device, struct device_info *info)          extensions[i] = (char *)info->extensions[i];      } -    free((void *)info->extensions); -              // we just added one more extension      create_info.enabledExtensionCount = info->ext_count+1;      create_info.ppEnabledExtensionNames = (const char * const *)extensions; @@ -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) { | 
