diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-11-01 16:48:20 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-11-01 16:48:20 +0100 |
| commit | 9bcef81cae01517f6298827630e7d53b4065fcf5 (patch) | |
| tree | b543a0c01cb05d7b981c95063c199012701dc53c /examples | |
| parent | 9d708a1b5a00b49463f284a19c23277f787c55df (diff) | |
Fix memory leaks in examples/shapedwindow.cxx
Note: usually we don't (need to) care for pseudo "leaks" at the end of
the program, we could just return, but this is a test and demo program.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/shapedwindow.cxx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/shapedwindow.cxx b/examples/shapedwindow.cxx index 36433fb13..22f3052b6 100644 --- a/examples/shapedwindow.cxx +++ b/examples/shapedwindow.cxx @@ -1,7 +1,7 @@ // // shapedwindow example source file for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2014 by Bill Spitzak and others. +// Copyright 1998-2024 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -93,7 +93,8 @@ int main(int argc, char **argv) { Fl_RGB_Image *img = prepare_shape(dim); win->shape(img); dragbox *box = new dragbox(0, 0, win->w(), win->h()); - box->image(new Fl_Tiled_Image(new Fl_Pixmap((const char * const *)tile_xpm))); + Fl_Pixmap *pxm = new Fl_Pixmap((const char * const *)tile_xpm); + box->bind_image(new Fl_Tiled_Image(pxm)); // Fl_Tiled_Image will be auto-released Fl_Group *g = new Fl_Group(10, 20, 80, 20); g->box(FL_NO_BOX); Fl_Button *b = new Fl_Button(10, 20, 80, 20, "Close"); @@ -113,7 +114,11 @@ int main(int argc, char **argv) { win->end(); win->resizable(win); win->show(argc, argv); - Fl::run(); + // Test for memory leaks: this is not necessary, it's just for demonstration. + // Memory checkers like Address Sanitizer or Valgrind would flag leaks. + int ret = Fl::run(); delete win; - return 0; + delete pxm; + delete img; + return ret; } |
