From ee34b376d768ecafc2fa21a79a854df503d1f115 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sun, 23 Oct 2011 00:01:45 +0200 Subject: Bugfix: clean up static resources correctly 93924af160ea303c94a2576b0e57a04e94c9228c might corrupt memory with gcc-4.6.1 when finishing fluxbox (clicking 'exit', sending it a SIGINT). Allthough the order, in which static / global objects are initialized is undefined (at least between separate compilation units), the order in which they are destroyed is well defined: in reverse order of initialization. this means, that if 'ScreenImlibContextContainer contexts' (of ImageImlib2.cc) gets initialized AFTER 'ImageImlib2 imlib2_loader' of Image.cc, it gets destroyed before imlib2_loader. When that happens, ~ImageImlib2() works on a destroyed object. (That lead to '* glibc detected * fluxbox: corrupted double-linked list: 0x0000000000dd2710 ***' later on in 'iconv_close') --- src/FbTk/ImageImlib2.cc | 23 +++++++++++------------ src/FbTk/ImageImlib2.hh | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/FbTk/ImageImlib2.cc b/src/FbTk/ImageImlib2.cc index 5bac7a4..69fc333 100644 --- a/src/FbTk/ImageImlib2.cc +++ b/src/FbTk/ImageImlib2.cc @@ -30,11 +30,20 @@ namespace { -typedef std::map ScreenImlibContextContainer; +class ScreenImlibContextContainer : public std::map { +public: + ~ScreenImlibContextContainer() { + + std::map::iterator it = this->begin(); + std::map::iterator it_end = this->end(); + for (; it != it_end; it++) { + imlib_context_free(it->second); + } + } +}; typedef ScreenImlibContextContainer::iterator ScreenImlibContext; ScreenImlibContextContainer contexts; - } // anon namespace @@ -69,16 +78,6 @@ ImageImlib2::ImageImlib2() { } } -ImageImlib2::~ImageImlib2() { - - ScreenImlibContext it = contexts.begin(); - ScreenImlibContext it_end = contexts.end(); - for (; it != it_end; it++) { - imlib_context_free(it->second); - } - contexts.clear(); -} - PixmapWithMask *ImageImlib2::load(const std::string &filename, int screen_num) const { Display *dpy = FbTk::App::instance()->display(); diff --git a/src/FbTk/ImageImlib2.hh b/src/FbTk/ImageImlib2.hh index 21bb854..b5da5a1 100644 --- a/src/FbTk/ImageImlib2.hh +++ b/src/FbTk/ImageImlib2.hh @@ -28,7 +28,6 @@ namespace FbTk { class ImageImlib2: public ImageBase { public: ImageImlib2(); - ~ImageImlib2(); PixmapWithMask *load(const std::string &filename, int screen_num) const; }; -- cgit v0.11.2