2

My first post here. I'm beginner programmer.

I'm compiling with clang 13.0.1. on Lenovo ThinkPad5 with AMD Ryzen 7 4800U with integrated Radeon Graphics OS: Manjaro linux with kernel 5.10.105 I'm using package allegro 5.2.7.0-2 My compile flags:

-Wall -Wextra -DDEBUG -g -fsanitize=address -fsanitize=undefined -fno-builtin -fno-omit-frame-pointer

I'm getting memory leak error from LeakSanitizer that looks like this:

=================================================================
==8886==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9dd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f04a62c5a2a  (/usr/lib/../lib/libGLX_mesa.so.0+0x3fa2a)

Indirect leak of 2544 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aacaab36 in __interceptor_posix_memalign /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:226
    #1 0x7f04a37cbe2a  (/usr/lib/dri/radeonsi_dri.so+0x991e2a)

Indirect leak of 1784 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a6205e7c in amdgpu_cs_ctx_create2 (/usr/lib/libdrm_amdgpu.so.1+0x4e7c)

Indirect leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a301a088  (/usr/lib/dri/radeonsi_dri.so+0x1e0088)

Indirect leak of 424 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a62d4343  (/usr/lib/../lib/libGLX_mesa.so.0+0x4e343)

Indirect leak of 264 byte(s) in 3 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a6204a88  (/usr/lib/libdrm_amdgpu.so.1+0x3a88)

Indirect leak of 240 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a62d74cc  (/usr/lib/../lib/libGLX_mesa.so.0+0x514cc)

Indirect leak of 208 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a381690f  (/usr/lib/dri/radeonsi_dri.so+0x9dc90f)

Indirect leak of 160 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a300eb1a  (/usr/lib/dri/radeonsi_dri.so+0x1d4b1a)

Indirect leak of 144 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a381a4e9  (/usr/lib/dri/radeonsi_dri.so+0x9e04e9)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a9941cc7 in xcb_register_for_special_xge (/usr/lib/libxcb.so.1+0xdcc7)

Indirect leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9dd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f04a9942b17  (/usr/lib/libxcb.so.1+0xeb17)

Indirect leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a620878a in amdgpu_va_range_alloc (/usr/lib/libdrm_amdgpu.so.1+0x778a)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a380ad1f  (/usr/lib/dri/radeonsi_dri.so+0x9d0d1f)
    #2 0x60700004d78f  (<unknown module>)

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9dd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f04a34cc841  (/usr/lib/dri/radeonsi_dri.so+0x692841)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f04aaca9fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f04a3814b1d  (/usr/lib/dri/radeonsi_dri.so+0x9dab1d)

Indirect leak of 32 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aaca9dd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f04a9942e06  (/usr/lib/libxcb.so.1+0xee06)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7f04aacaa1b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x7f04a38157d1  (/usr/lib/dri/radeonsi_dri.so+0x9db7d1)

SUMMARY: AddressSanitizer: 6776 byte(s) leaked in 29 allocation(s).

Maybe I'm missing something important and not deallocating something allocated by allegro functions but I can't find anything in the documentation. My code on github: https://github.com/artqs01/gravity-game.

My code looks like this in the main() function:

int main()
{
    srand(time(0));

    // Checking if things fail to init
    allegro_init();

    // Timer init
    ALLEGRO_TIMER* timer =  al_create_timer(0.013);
    al_start_timer(timer);

    // Display init
    ALLEGRO_DISPLAY* d = al_create_display(1200, 900);
    al_clear_to_color(al_map_rgb(0, 0, 0));

    // Event queue init
    ALLEGRO_EVENT_QUEUE* eq = al_create_event_queue();
    ALLEGRO_EVENT e;
    allegro_register_events(eq, d, timer);

    //Font init
    ALLEGRO_FONT* font = al_load_ttf_font("../fonts/consola.ttf", 20, 0);
    if (!font)
    {
        printf("font not loaded\n");
        return 1;
    }
    
    //Mouse control init
    ALLEGRO_MOUSE_STATE cur_ms;
    al_get_mouse_state(&cur_ms);
    ALLEGRO_MOUSE_STATE prev_ms;

    //Camera transformation init
    ALLEGRO_TRANSFORM transf;
    ctrl_cam_ctrler c_ctrl = ctrl_create_cam_ctrler();

    // Main loop control variable init
    ctrl_loop_ctrler l_ctrl = ctrl_create_loop_ctrler();

    // Time measure variable init
    ctrl_time_ctrler t_ctrl = ctrl_create_time_ctrler();

    obj arro[2];
    arro[0] = obj_create(20.f, 1000.f, -1000.f, (vect2){300.f, 300.f}, (vect2){10.f, 0.f});
    arro[1] = obj_create(10.f, 100.f, 1000.f, (vect2){600.f, 600.f}, (vect2){0.f, -10.f});
    const int size = sizeof(arro) / sizeof(obj);

    // Main loop
    while (l_ctrl.alive)
    {
        ctrl_measure_dt(&t_ctrl);
        al_wait_for_event(eq, &e);
        ctrl_manage_event(eq, &e, &l_ctrl);
        if (!l_ctrl.pause)
        {
            obj_update(arro, size, t_ctrl.dt);
        }
        if (l_ctrl.step)
        {
            l_ctrl.pause = 1;
            l_ctrl.step = 0;
        }
        ctrl_set_zoom(&cur_ms, &prev_ms, &c_ctrl);
        ctrl_transform(&transf, &c_ctrl);
        ctrl_mouse_state_update(&cur_ms, &prev_ms, &c_ctrl);
        draw(arro, size, font);
        al_flip_display();
    }

    // Cleaning up
    al_destroy_display(d);
    al_destroy_event_queue(eq);
    al_destroy_timer(timer);
    al_destroy_font(font);
    return 0;
}

Maybe You know if it's something related to my poorly written code or the graphics driver. I'm getting similar leaks on my desktop with Intel core i5 4460 and Geforce GTX 970 (same OS).

Thanks!

artqs01
  • 21
  • 3
  • 1
    It's hard to relate the reported leaks to your high level code. I'd start by commenting out some 99% of the code except one function call with it's corresponding clean-up call, see if there are leaks reported, and if not enable the next function. Also don't rule out false positives by the tool. – Lundin Apr 26 '22 at 08:52

0 Answers0