Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Likely memory leaks #2546

Open
quadroli opened this issue Apr 28, 2024 · 1 comment
Open

Likely memory leaks #2546

quadroli opened this issue Apr 28, 2024 · 1 comment

Comments

@quadroli
Copy link

quadroli commented Apr 28, 2024

Hello,
I'm running GLFW on master, currently at commit b35641f4a3c62aa86a0b3c983d163bc0fe36026d and,
while running valgrind on my program, via the command valgrind --leak-check=full ./a.out, both the Wayland version and X11 versions seem to be leaking memory, however X11 leaks only 408 bytes while the Wayland version is leaking significantly more. I have included the source file, and both valgrind reports on the Wayland and X11 versions, any assistance and/or further clarification/guidance will be highly appreciated, thank you.

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define GLAD_GL_IMPLEMENTATION
#include "lib/gl.h"
#include <GLFW/glfw3.h>
#define WIDTH 800
#define HEIGHT 600
void processInput(GLFWwindow *window);
void framebufferSizeCallback(GLFWwindow *window, int width, int height);
int main(void){
  glfwInit();
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
  if(window == NULL) { 
    printf("FAILED to initialize GLFW window\n");
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
  glfwMakeContextCurrent(window);
  glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
  if(!gladLoadGL((GLADloadfunc)glfwGetProcAddress)){
    printf("OpenGL: failed to init!\n");
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
  while (!glfwWindowShouldClose(window)) {
    processInput(window);
    glClearColor(0.2f, 0.3f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers(window);
    glfwPollEvents();
  }
  glfwTerminate();
  return 0;
}
void processInput(GLFWwindow *window){
  if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true);
}
void framebufferSizeCallback(GLFWwindow *window, int width, int height){
  glViewport(0,0, width, height);
}
Wayland report ==17605== Memcheck, a memory error detector

==17605== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==17605== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright info
==17605== Command: ./a.out
==17605==
==17605==
==17605== HEAP SUMMARY:
==17605== in use at exit: 1,056,715 bytes in 10,374 blocks
==17605== total heap usage: 48,653 allocs, 38,279 frees, 19,152,892 bytes allocated
==17605==
==17605== 8 bytes in 1 blocks are definitely lost in loss record 65 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x509668E: libdecor_plugin_init (in /usr/lib/x86_64-linux-gnu/libdecor-0.so.0.100.0)
==17605== by 0x4867B71: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x50972AE: libdecor_new (in /usr/lib/x86_64-linux-gnu/libdecor-0.so.0.100.0)
==17605== by 0x48A98B0: _glfwInitWayland (in /usr/local/lib/libglfw.so.3.5)
==17605== by 0x488501E: glfwInit (in /usr/local/lib/libglfw.so.3.5)
==17605== by 0x10BA23: main (in /home/mela/Art/Learn/OpenGL/a.out)
==17605==
==17605== 24 bytes in 1 blocks are possibly lost in loss record 306 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x53D4D05: FcFontRenderPrepare (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56BB4E6: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x5750A50: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x49A0AC2: start_thread (pthread_create.c:442)
==17605== by 0x4A31A03: clone (clone.S:100)
==17605==
==17605== 26 bytes in 1 blocks are possibly lost in loss record 327 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x572AC50: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x5212193: pango_language_from_string (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5212298: pango_language_get_default (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214CBB: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5291FB9: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7200.4)
==17605== by 0x52790EC: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7200.4)
==17605== by 0x527A34C: g_object_new_with_properties (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7200.4)
==17605== by 0x527AE50: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7200.4)
==17605== by 0x5210BE7: pango_font_map_create_context (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x51E738F: pango_cairo_create_context (in /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0.5000.6)
==17605== by 0x51E73F4: pango_cairo_create_layout (in /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0.5000.6)
==17605==
==17605== 32 bytes in 2 blocks are possibly lost in loss record 658 of 3,073
==17605== at 0x484880F: malloc (vg_replace_malloc.c:444)
==17605== by 0x53D02B9: FcFontSetSort (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56BB580: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x5750A50: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x49A0AC2: start_thread (pthread_create.c:442)
==17605== by 0x4A31A03: clone (clone.S:100)
==17605==
==17605== 96 bytes in 1 blocks are possibly lost in loss record 2,780 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x572AC50: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x5777B44: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x56C0539: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x520C240: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521F3DE: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214925: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214AF9: pango_layout_get_size (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x4864299: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x4865C66: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x4865F02: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x48AE7E7: createLibdecorFrame (in /usr/local/lib/libglfw.so.3.5)
==17605==
==17605== 96 bytes in 1 blocks are possibly lost in loss record 2,781 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x572AC50: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x5777B44: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x56C0539: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x520C240: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521F3DE: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214925: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x51E3BCD: ??? (in /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0.5000.6)
==17605== by 0x521DDEC: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521E2DF: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214509: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x52148B6: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605==
==17605== 834 (512 direct, 322 indirect) bytes in 2 blocks are definitely lost in loss record 2,949 of 3,073
==17605== at 0x484880F: malloc (vg_replace_malloc.c:444)
==17605== by 0x53CCA21: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53CF590: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53D9B7C: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x5BA9B66: ??? (in /usr/lib/x86_64-linux-gnu/libexpat.so.1.8.7)
==17605== by 0x5BA7ECD: ??? (in /usr/lib/x86_64-linux-gnu/libexpat.so.1.8.7)
==17605== by 0x5BA8DBB: ??? (in /usr/lib/x86_64-linux-gnu/libexpat.so.1.8.7)
==17605== by 0x5BA04E7: ??? (in /usr/lib/x86_64-linux-gnu/libexpat.so.1.8.7)
==17605== by 0x5BACF93: XML_ParseBuffer (in /usr/lib/x86_64-linux-gnu/libexpat.so.1.8.7)
==17605== by 0x53DB332: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53DBAE8: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53DBC9D: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605==
==17605== 2,856 (2,672 direct, 184 indirect) bytes in 1 blocks are definitely lost in loss record 3,025 of 3,073
==17605== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==17605== by 0x6D3A826: ???
==17605== by 0x6D3AECF: ???
==17605== by 0x6C5BF64: ???
==17605== by 0x4890D11: _glfwInitEGL (in /usr/local/lib/libglfw.so.3.5)
==17605== by 0x48B1A35: _glfwCreateWindowWayland (in /usr/local/lib/libglfw.so.3.5)
==17605== by 0x488CE1B: glfwCreateWindow (in /usr/local/lib/libglfw.so.3.5)
==17605== by 0x10BA6E: main (in /home/mela/Art/Learn/OpenGL/a.out)
==17605==
==17605== 3,072 bytes in 2 blocks are possibly lost in loss record 3,028 of 3,073
==17605== at 0x4850184: realloc (vg_replace_malloc.c:1722)
==17605== by 0x53C2EB3: FcFontSetAdd (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53D03A4: FcFontSetSort (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56BB580: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x5750A50: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x49A0AC2: start_thread (pthread_create.c:442)
==17605== by 0x4A31A03: clone (clone.S:100)
==17605==
==17605== 4,841 (1,536 direct, 3,305 indirect) bytes in 2 blocks are definitely lost in loss record 3,046 of 3,073
==17605== at 0x4850184: realloc (vg_replace_malloc.c:1722)
==17605== by 0x53CCAC0: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53DBE52: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53D52BC: FcFontRenderPrepare (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56BB4E6: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x5750A50: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7200.4)
==17605== by 0x49A0AC2: start_thread (pthread_create.c:442)
==17605== by 0x4A31A03: clone (clone.S:100)
==17605==
==17605== 6,851 (512 direct, 6,339 indirect) bytes in 1 blocks are definitely lost in loss record 3,054 of 3,073
==17605== at 0x4850184: realloc (vg_replace_malloc.c:1722)
==17605== by 0x53CCAC0: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53CF590: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53C82D6: FcDefaultSubstitute (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56C030D: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x520C240: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521F3DE: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214925: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214AF9: pango_layout_get_size (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x4864299: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x4865C66: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605== by 0x4865F02: ??? (in /usr/lib/x86_64-linux-gnu/libdecor/plugins-1/libdecor-cairo.so)
==17605==
==17605== 6,986 (512 direct, 6,474 indirect) bytes in 1 blocks are definitely lost in loss record 3,055 of 3,073
==17605== at 0x4850184: realloc (vg_replace_malloc.c:1722)
==17605== by 0x53CCAC0: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53CF590: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x53C82D6: FcDefaultSubstitute (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0)
==17605== by 0x56C030D: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.5000.6)
==17605== by 0x520C240: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521F3DE: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214925: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x51E3BCD: ??? (in /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0.5000.6)
==17605== by 0x521DDEC: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x521E2DF: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605== by 0x5214509: ??? (in /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6)
==17605==
==17605== LEAK SUMMARY:
==17605== definitely lost: 5,752 bytes in 8 blocks
==17605== indirectly lost: 16,624 bytes in 674 blocks
==17605== possibly lost: 3,346 bytes in 8 blocks
==17605== still reachable: 1,027,305 bytes in 9,648 blocks
==17605== suppressed: 416 bytes in 2 blocks
==17605== Reachable blocks (those to which a pointer was found) are not shown.
==17605== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==17605==
==17605== For lists of detected and suppressed errors, rerun with: -s
==17605== ERROR SUMMARY: 12 errors from 12 contexts (suppressed: 0 from 0)

X11 report ==19179== Memcheck, a memory error detector

==19179== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==19179== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright info
==19179== Command: ./a.out
==19179==
==19179==
==19179== HEAP SUMMARY:
==19179== in use at exit: 325,311 bytes in 3,102 blocks
==19179== total heap usage: 17,056 allocs, 13,954 frees, 5,287,580 bytes allocated
==19179==
==19179== 0 bytes in 2 blocks are definitely lost in loss record 1 of 2,232
==19179== at 0x484880F: malloc (vg_replace_malloc.c:444)
==19179== by 0x4005A22: malloc (rtld-malloc.h:56)
==19179== by 0x4005A22: _dl_find_object_update (dl-find_object.c:791)
==19179== by 0x400ECCF: dl_open_worker_begin (dl-open.c:735)
==19179== by 0x4A80A97: _dl_catch_exception (dl-error-skeleton.c:208)
==19179== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19179== by 0x4A80A97: _dl_catch_exception (dl-error-skeleton.c:208)
==19179== by 0x400E34D: _dl_open (dl-open.c:883)
==19179== by 0x499C63B: dlopen_doit (dlopen.c:56)
==19179== by 0x4A80A97: _dl_catch_exception (dl-error-skeleton.c:208)
==19179== by 0x4A80B62: _dl_catch_error (dl-error-skeleton.c:227)
==19179== by 0x499C12D: _dlerror_run (dlerror.c:138)
==19179== by 0x499C6C7: dlopen_implementation (dlopen.c:71)
==19179== by 0x499C6C7: dlopen@@GLIBC_2.34 (dlopen.c:81)
==19179==
==19179== 408 bytes in 1 blocks are definitely lost in loss record 2,204 of 2,232
==19179== at 0x484FF70: calloc (vg_replace_malloc.c:1597)
==19179== by 0x5F859CF: _XimOpenIM (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==19179== by 0x5F8B57C: _XimRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==19179== by 0x5F77BAC: XRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0)
==19179== by 0x489A27C: _glfwInitX11 (in /usr/local/lib/libglfw.so.3.5)
==19179== by 0x488501E: glfwInit (in /usr/local/lib/libglfw.so.3.5)
==19179== by 0x10BA23: main (in /home/mela/Art/Learn/OpenGL/a.out)
==19179==
==19179== LEAK SUMMARY:
==19179== definitely lost: 408 bytes in 3 blocks
==19179== indirectly lost: 0 bytes in 0 blocks
==19179== possibly lost: 0 bytes in 0 blocks
==19179== still reachable: 324,871 bytes in 3,098 blocks
==19179== suppressed: 32 bytes in 1 blocks
==19179== Reachable blocks (those to which a pointer was found) are not shown.
==19179== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==19179==
==19179== For lists of detected and suppressed errors, rerun with: -s
==19179== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

PS: I'm running this on Pop!_OS 22.04
I confirmed the reports are identical on the latest release 3.4 as well.

@quadroli
Copy link
Author

quadroli commented May 13, 2024

I ought to mention though that the report is different on Alpine Linux while using the river compositor, in terms of no apparent memory leak is reported

Wayland report on Alpine Linux, using river ==6587== Memcheck, a memory error detector

==6587== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==6587== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==6587== Command: ./runnable/helloWindow
==6587==
==6587==
==6587== HEAP SUMMARY:
==6587== in use at exit: 211,706 bytes in 2,091 blocks
==6587== total heap usage: 20,831 allocs, 18,740 frees, 3,909,334 bytes allocated
==6587==
==6587== LEAK SUMMARY:
==6587== definitely lost: 0 bytes in 0 blocks
==6587== indirectly lost: 0 bytes in 0 blocks
==6587== possibly lost: 0 bytes in 0 blocks
==6587== still reachable: 211,706 bytes in 2,091 blocks
==6587== suppressed: 0 bytes in 0 blocks
==6587== Reachable blocks (those to which a pointer was found) are not shown.
==6587== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6587==
==6587== For lists of detected and suppressed errors, rerun with: -s
==6587== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant