Memory leak in basic freeglut program

Viewed 44

I'm trying to make a simple freeglut application. I have the following code:

#include "GL/freeglut.h"
#include "glm/glm.hpp"

// global and state variables
namespace globals {
  const int screen_width = 720;
  const int screen_height = 720;
  const int window_position_x = 100;
  const int window_position_y = 100;

  const glm::vec4 clear_color (0.2f, 0.2f, 0.2f, 1.0f);
}

void display ();

int main (int argc, char** argv) {glutInit(&argc, argv);
  // initialize GLUT window size, position, display mode
  glutInitWindowSize(globals::screen_width, globals::screen_height);
  glutInitWindowPosition(globals::window_position_x, globals::window_position_y);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

  // continue execution after window is closed by user
  glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

  // create a window
  glutCreateWindow("Simple GLUT Template");

  // setup a display callback that GLUT calls for every render
  glutDisplayFunc(display);

  // start main loop
  glutMainLoop();

  return 0;
}

void display () {
  using namespace globals;

  glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_color.a);
  glClear(GL_COLOR_BUFFER_BIT);

  glutSwapBuffers();
}

I initialise the program to work with GLUT and create a simple window. For compilation, I use this:

g++ -Wall -Wextra -pedantic -g -DDEBUG_MODE -D_GLIBCXX_DEBUG -fsanitize=address,undefined -lGL -lGLU -lglut simple-glut-template.cpp -o simple-glut-template

When I execute the program and close the window, the address sanitizer seems to pick up on a lot of memory leakage that I cannot seem to fix (output shared below). Any help on understanding what's happening is appreciated. Thanks!

Memory leak found by Address Sanitizer:

=================================================================
==24070==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 1264 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f2998557701  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd57701)
    #2 0x7f299855a86c  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd5a86c)

Indirect leak of 632 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f2998557701  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd57701)
    #2 0x7f299855a1d7  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd5a1d7)

Indirect leak of 520 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f29978b2317  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xb2317)

Indirect leak of 416 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299ba65b04  (/lib/x86_64-linux-gnu/libGLX_mesa.so.0+0x42b04)

Indirect leak of 416 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299854729e  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4729e)
    #2 0x7f2998549caf  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd49caf)
    #3 0x7f299855a8eb  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd5a8eb)

Indirect leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299ba7187f  (/lib/x86_64-linux-gnu/libGLX_mesa.so.0+0x4e87f)

Indirect leak of 96 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299854e18c  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4e18c)

Indirect leak of 96 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b78d5 in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85
    #1 0x7f299855df80  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd5df80)
    #2 0x7f299854cf16  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4cf16)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f29978ad39d  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xad39d)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299c3009ce in xcb_register_for_special_xge (/lib/x86_64-linux-gnu/libxcb.so.1+0xe9ce)

Indirect leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f299c301872  (/lib/x86_64-linux-gnu/libxcb.so.1+0xf872)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f29978b55fc  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xb55fc)

Indirect leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f299854cd45  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4cd45)

Indirect leak of 32 byte(s) in 2 object(s) allocated from:
    #0 0x7f299c8b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f299c301ab5  (/lib/x86_64-linux-gnu/libxcb.so.1+0xfab5)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f299c8b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f299854d7aa  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4d7aa)
    #2 0x7f299855d270  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd5d270)
    #3 0x7f299854ca7f  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0xd4ca7f)
    #4 0x7f2997985729  (/usr/lib/x86_64-linux-gnu/dri/iris_dri.so+0x185729)

SUMMARY: AddressSanitizer: 3952 byte(s) leaked in 21 allocation(s).
0 Answers
Related