From 9bcef81cae01517f6298827630e7d53b4065fcf5 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 1 Nov 2024 16:48:20 +0100 Subject: 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. --- examples/shapedwindow.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'examples') 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; } -- cgit v1.2.3