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

Detected a memory leak. #921

Closed
llcxiongmao opened this issue Feb 27, 2024 · 1 comment
Closed

Detected a memory leak. #921

llcxiongmao opened this issue Feb 27, 2024 · 1 comment

Comments

@llcxiongmao
Copy link

Environment: Windows 10, 64bit, vs2022.

reproduce code:

#include <memory>

#include <Windows.h>
#include <crtdbg.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
	// enable memory leak check.
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	// _CrtSetBreakAlloc(162);

	std::unique_ptr<Fl_Window> win = std::make_unique<Fl_Window>(0, 0, 800, 600);
	win->show();

	Fl::run();

	win = nullptr;
	return 0;
}

leak position:src/Fl.cxx#1852, code:

void Fl::watch_widget_pointer(Fl_Widget *&w)
{
  Fl_Widget **wp = &w;
  int i;
  for (i=0; i<num_widget_watch; ++i) {
    if (widget_watch[i]==wp) return;
  }
  if (num_widget_watch==max_widget_watch) {
    max_widget_watch += 8;
    // widget_watch leaked.
    widget_watch = (Fl_Widget***)realloc(widget_watch, sizeof(Fl_Widget**)*max_widget_watch);
  }
  widget_watch[num_widget_watch++] = wp;
#ifdef DEBUG_WATCH
  printf ("\nwatch_widget_pointer:   (%d/%d) %8p => %8p\n",
    num_widget_watch,num_widget_watch,wp,*wp);
  fflush(stdout);
#endif // DEBUG_WATCH
}

i scan the entire project, find widget_watch never be freed.

@ManoloFLTK
Copy link
Contributor

Thanks for reporting this finding.

That's how the FLTK library works. There are many places where FLTK allocates some memory, to hold a character string for example, and uses and re-uses that memory for the functioning of the library, and never releases it. That is to be considered part of the resources required by FLTK to access the OS and its displays. These are not memory leaks.

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

2 participants