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

3 Memory Leaks on Windows #1143

Closed
TheAifam5 opened this Issue Sep 4, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@TheAifam5

TheAifam5 commented Sep 4, 2016

Version: SFML 2.4.0
Log:

WARNING: Visual Leak Detector detected memory leaks!
---------- Block 12 at 0x015A5568: 52 bytes ----------
  Leak Hash: 0x44413431, Count: 1, Total 52 bytes
  Call Stack (TID 4828):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): BrutalemPrzezTeamspeak.exe!operator new() + 0x9 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (182): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::globalInit() + 0x7 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glresource.cpp (56): BrutalemPrzezTeamspeak.exe!sf::GlResource::GlResource()
    d:\sfml-release\_sources\sfml\src\sfml\window\window.cpp (49): BrutalemPrzezTeamspeak.exe!sf::Window::Window() + 0x38 bytes
    d:\sfml-release\_sources\sfml\src\sfml\graphics\renderwindow.cpp (43): BrutalemPrzezTeamspeak.exe!sf::RenderWindow::RenderWindow() + 0x35 bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\application.cpp (6): BrutalemPrzezTeamspeak.exe!Application::Application() + 0xDB bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\main.cpp (6): BrutalemPrzezTeamspeak.exe!main() + 0xB bytes
    BrutalemPrzezTeamspeak.exe!WinMain() + 0x2D bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (99): BrutalemPrzezTeamspeak.exe!invoke_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (253): BrutalemPrzezTeamspeak.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (296): BrutalemPrzezTeamspeak.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_winmain.cpp (17): BrutalemPrzezTeamspeak.exe!WinMainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x439 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x404 bytes
  Data:
    50 BB 03 01    18 00 00 00    00 00 00 00    00 00 00 00     P....... ........
    04 00 00 00    05 00 00 00    00 00 00 00    00 CC CC CC     ........ ........
    DE 11 0F 00    00 00 00 00    D2 22 01 43    00 00 01 00     ........ .".C....
    01 CD CD CD                                                  ........ ........


---------- Block 14 at 0x015A5928: 52 bytes ----------
  Leak Hash: 0x332931C6, Count: 1, Total 52 bytes
  Call Stack (TID 4828):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): BrutalemPrzezTeamspeak.exe!operator new() + 0x9 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (227): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::create() + 0x7 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\context.cpp (62): BrutalemPrzezTeamspeak.exe!sf::Context::Context() + 0x5 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (159): BrutalemPrzezTeamspeak.exe!`anonymous namespace'::getInternalContext() + 0x22 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (334): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::setActive() + 0x7 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (189): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::globalInit()
    d:\sfml-release\_sources\sfml\src\sfml\window\glresource.cpp (56): BrutalemPrzezTeamspeak.exe!sf::GlResource::GlResource()
    d:\sfml-release\_sources\sfml\src\sfml\window\window.cpp (49): BrutalemPrzezTeamspeak.exe!sf::Window::Window() + 0x38 bytes
    d:\sfml-release\_sources\sfml\src\sfml\graphics\renderwindow.cpp (43): BrutalemPrzezTeamspeak.exe!sf::RenderWindow::RenderWindow() + 0x35 bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\application.cpp (6): BrutalemPrzezTeamspeak.exe!Application::Application() + 0xDB bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\main.cpp (6): BrutalemPrzezTeamspeak.exe!main() + 0xB bytes
    BrutalemPrzezTeamspeak.exe!WinMain() + 0x2D bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (99): BrutalemPrzezTeamspeak.exe!invoke_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (253): BrutalemPrzezTeamspeak.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (296): BrutalemPrzezTeamspeak.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_winmain.cpp (17): BrutalemPrzezTeamspeak.exe!WinMainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x439 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x404 bytes
  Data:
    50 BB 03 01    00 00 00 00    00 00 00 00    00 00 00 00     P....... ........
    04 00 00 00    05 00 00 00    00 00 00 00    00 CC CC CC     ........ ........
    DE 11 0F 00    BA F6 09 A8    8F 15 01 2E    01 00 01 00     ........ ........
    00 CD CD CD                                                  ........ ........


---------- Block 13 at 0x015C0368: 8 bytes ----------
  Leak Hash: 0xF8E74C1E, Count: 1, Total 8 bytes
  Call Stack (TID 4828):
    ucrtbased.dll!malloc()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): BrutalemPrzezTeamspeak.exe!operator new() + 0x9 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (159): BrutalemPrzezTeamspeak.exe!`anonymous namespace'::getInternalContext() + 0x7 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (334): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::setActive() + 0x7 bytes
    d:\sfml-release\_sources\sfml\src\sfml\window\glcontext.cpp (189): BrutalemPrzezTeamspeak.exe!sf::priv::GlContext::globalInit()
    d:\sfml-release\_sources\sfml\src\sfml\window\glresource.cpp (56): BrutalemPrzezTeamspeak.exe!sf::GlResource::GlResource()
    d:\sfml-release\_sources\sfml\src\sfml\window\window.cpp (49): BrutalemPrzezTeamspeak.exe!sf::Window::Window() + 0x38 bytes
    d:\sfml-release\_sources\sfml\src\sfml\graphics\renderwindow.cpp (43): BrutalemPrzezTeamspeak.exe!sf::RenderWindow::RenderWindow() + 0x35 bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\application.cpp (6): BrutalemPrzezTeamspeak.exe!Application::Application() + 0xDB bytes
    d:\projects\brutalemprzezteamspeak\brutalemprzezteamspeak\main.cpp (6): BrutalemPrzezTeamspeak.exe!main() + 0xB bytes
    BrutalemPrzezTeamspeak.exe!WinMain() + 0x2D bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (99): BrutalemPrzezTeamspeak.exe!invoke_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (253): BrutalemPrzezTeamspeak.exe!__scrt_common_main_seh() + 0x5 bytes
    f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (296): BrutalemPrzezTeamspeak.exe!__scrt_common_main()
    f:\dd\vctools\crt\vcstartup\src\startup\exe_winmain.cpp (17): BrutalemPrzezTeamspeak.exe!WinMainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x439 bytes
    ntdll.dll!RtlSubscribeWnfStateChangeNotification() + 0x404 bytes
  Data:
    CD CD CD CD    28 59 5A 01                                   ....(YZ. ........


Visual Leak Detector detected 3 memory leaks (220 bytes).
@nabijaczleweli

This comment has been minimized.

Show comment
Hide comment
@nabijaczleweli

nabijaczleweli Sep 4, 2016

BrutalemPrzezTeamspeak.exe please don't, though?

nabijaczleweli commented Sep 4, 2016

BrutalemPrzezTeamspeak.exe please don't, though?

@binary1248

This comment has been minimized.

Show comment
Hide comment
@binary1248

binary1248 Sep 4, 2016

Member

Visual Leak Detector is known to check for leaks too early (before static/global destructors are called). This results in the same false positives being reported over and over again. Next time instead of blindly trusting certain tools, please review their results yourself to confirm that they are actual leaks before reporting them. Thank you.

Member

binary1248 commented Sep 4, 2016

Visual Leak Detector is known to check for leaks too early (before static/global destructors are called). This results in the same false positives being reported over and over again. Next time instead of blindly trusting certain tools, please review their results yourself to confirm that they are actual leaks before reporting them. Thank you.

@TheAifam5

This comment has been minimized.

Show comment
Hide comment
@TheAifam5

TheAifam5 Sep 5, 2016

Gonna use CRT library.
@nabijaczleweli wut?

TheAifam5 commented Sep 5, 2016

Gonna use CRT library.
@nabijaczleweli wut?

@hobby8

This comment has been minimized.

Show comment
Hide comment
@hobby8

hobby8 Sep 9, 2016

Contributor

These leaks were reported months ago on a pre-2.4 version (discussion here). They are reported not only by VLD but also by the CRT.

If you don't trust leak detection tools or debuggers in general, here's what you can do:

  • Build SFML 2.4 from source on Windows. Choose static linking.
  • Modify WglContext so that the default c'tors are not created by the compiler.
  • Modify the implementation of WglContext d'tor and 3 c'tors so that they append a line to a file.

Took only a few minutes, here's the output:
c'tor 005922D0
c'tor 02E2B760
c'tor 02E39268
d'tor 02E39268

==> the leaks are real.

Contributor

hobby8 commented Sep 9, 2016

These leaks were reported months ago on a pre-2.4 version (discussion here). They are reported not only by VLD but also by the CRT.

If you don't trust leak detection tools or debuggers in general, here's what you can do:

  • Build SFML 2.4 from source on Windows. Choose static linking.
  • Modify WglContext so that the default c'tors are not created by the compiler.
  • Modify the implementation of WglContext d'tor and 3 c'tors so that they append a line to a file.

Took only a few minutes, here's the output:
c'tor 005922D0
c'tor 02E2B760
c'tor 02E39268
d'tor 02E39268

==> the leaks are real.

@binary1248

This comment has been minimized.

Show comment
Hide comment
@binary1248

binary1248 Sep 10, 2016

Member

Hmm... yes... I can see that a circular reference is preventing the GlResource reference count from dropping down to 0 when it should. This prevents the internal contexts from being freed during de-initialization. This can be considered a leak, however because the contexts would have only been freed during termination anyway, this is less serious than a leak that would lead to memory usage building up during run time.

This will be fixed eventually. Probably when the no_internal_context branch gets accepted and merged, so there probably won't be a separate effort to fix this issue in the mean time.

Member

binary1248 commented Sep 10, 2016

Hmm... yes... I can see that a circular reference is preventing the GlResource reference count from dropping down to 0 when it should. This prevents the internal contexts from being freed during de-initialization. This can be considered a leak, however because the contexts would have only been freed during termination anyway, this is less serious than a leak that would lead to memory usage building up during run time.

This will be fixed eventually. Probably when the no_internal_context branch gets accepted and merged, so there probably won't be a separate effort to fix this issue in the mean time.

@binary1248 binary1248 reopened this Sep 10, 2016

@binary1248 binary1248 self-assigned this Sep 10, 2016

@binary1248 binary1248 added this to the 2.4.1 milestone Oct 2, 2016

@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r Oct 6, 2016

Member

Should be fix with cca38d9 in the 2.4.x branch.

Member

eXpl0it3r commented Oct 6, 2016

Should be fix with cca38d9 in the 2.4.x branch.

@eXpl0it3r eXpl0it3r closed this Oct 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment