libsdl-org / sdl12-compat

An SDL-1.2 compatibility layer that uses SDL 2.0 behind the scenes.
Other
193 stars 40 forks source link

[Git main] SDL_SetVideoMode does not fully free the surface created by a previous call to SDL_SetVideoMode but should? #285

Closed hartwork closed 1 year ago

hartwork commented 1 year ago

Hi!

This is strongly related to #284 but concerns SDL_SetVideoMode itself on Git main (at db10d6fc01a2a567ddf58e9890b3bbeb6fa5c77c over here). This time my test program is this:

// main.c
#include <SDL.h>

int main() {
  SDL_Init(SDL_INIT_EVERYTHING);
  SDL_SetVideoMode(640, 480, 32, SDL_RESIZABLE);
  SDL_SetVideoMode(640, 480, 32, SDL_RESIZABLE);  // second time, normally called on window resize
  SDL_Quit();
  return 0;
}

I am building like this (with no Makefile present):

# make main \
    CFLAGS="$(pkg-config sdl12_compat --cflags) -g -fsanitize=address -fno-omit-frame-pointer" \
    LDFLAGS="$(pkg-config sdl12_compat --libs) -g -fsanitize=address -fno-omit-frame-pointer" \
  && ./main

The output I get is this:

=================================================================
==7842==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7fbea0a87aff in __interceptor_calloc [..]/gcc-11-20221223/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fbe9cea6721 in SDL_calloc_REAL [..]/sdl2/src/stdlib/SDL_malloc.c:5308
    #2 0x56065c18819b in main /tmp/tmp.bPvwZKpCkR/main.c:6
    #3 0x7fbea079e209  (/lib64/libc.so.6+0x2a209)

SUMMARY: AddressSanitizer: 40 byte(s) leaked in 1 allocation(s).

From my understanding, the second call to SDL_SetVideoMode is supposed to fully clean up the previous surface. It seems to do that with SDL 1.2 but not with sdl12-compat.

What do you think?

Best, Sebastian

hartwork commented 1 year ago

@icculus I confirm it's fixed by b2f7b7736b4adaba2805e5d2979c51676ee950ce, thank you! :+1: