# Memory leak in glfwGetRequiredInstanceExt

**URL:** <https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355>\
**Category:** support\
**Created:** [April 15, 2023, 3:37pm UTC](https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355 "2023-04-15T15:37:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adobriyan](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@adobriyan](https://discourse.glfw.org/u/adobriyan)\
**Post date:** [April 15, 2023, 3:37pm UTC](https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355/1 "2023-04-15T15:37:20Z")

</div>

This minimal glfw program leaks memory according to valgrind.  
But returned pointer is not allocated, attempt to free will trigger double free/corruption in glibc.

glfwInit();  
uint32\_t n;  
const char\*\* glfw\_extension\_list = glfwGetRequiredInstanceExtensions(&n);  
glfwTerminate();

==408378== HEAP SUMMARY:  
==408378== in use at exit: 278,892 bytes in 2,880 blocks  
==408378== total heap usage: 24,344 allocs, 21,464 frees, 451,741,092 bytes allocated  
==408378==  
==408378== LEAK SUMMARY:  
==408378== definitely lost: 1,120 bytes in 20 blocks  
==408378== indirectly lost: 2,818 bytes in 63 blocks  
==408378== possibly lost: 0 bytes in 0 blocks  
==408378== still reachable: 274,954 bytes in 2,797 blocks  
==408378== suppressed: 0 bytes in 0 blocks

It is kind of not cool because I can’t tell my leaks from glfw leaks.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 17, 2023, 5:10pm UTC](https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355/2 "2023-04-17T17:10:57Z")

</div>

The function `glfwGetRequiredInstanceExtensions()` does not allocate any memory, it simply returns the address of the strings stored in the `_GLFWlibrary _glfw ` variable.

It is possible that `glfwInit()`, `glfwTerminate()` are leaking, but it’s also possible that any of the libraries that these use have a leak.

---

<div class="post-metadata">

**Author:** ![adobriyan](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@adobriyan](https://discourse.glfw.org/u/adobriyan)\
**Post date:** [April 18, 2023, 5:16am UTC](https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355/3 "2023-04-18T05:16:03Z")

</div>

Trivial glfwInit/glfwTerminate doesn’t leak:  
==3253== definitely lost: 0 bytes in 0 blocks

Trivial glfwInit/glfwGetRequiredInstanceExtensions/glfwTerminate program leaks:  
==3293== definitely lost: 1,120 bytes in 20 blocks

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 18, 2023, 10:23am UTC](https://discourse.glfw.org/t/memory-leak-in-glfwgetrequiredinstanceext/2355/4 "2023-04-18T10:23:34Z")

</div>

Stepping through the code I missed that `glfwGetRequiredInstanceExtensions()` calls `_glfwInitVulkan()` which loads the vulkan library dynamically, and then queries extensions.

Checking through the code on Win32 the GLFW library itself does not leak (most of the code here is cross platform so I assume this is also the case on other platforms) but the Vulkan library or GPU driver libraries might.
