all repos — fluxbox @ ee34b376d768ecafc2fa21a79a854df503d1f115

custom fork of the fluxbox windowmanager

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')
Mathias Gumz akira at fluxbox dot org
commit

ee34b376d768ecafc2fa21a79a854df503d1f115

parent

3f76e117bf7735058f2b135beb72e015658f97eb

2 files changed, 11 insertions(+), 13 deletions(-)

jump to
M src/FbTk/ImageImlib2.ccsrc/FbTk/ImageImlib2.cc

@@ -30,11 +30,20 @@ #include <iostream>

namespace { -typedef std::map<int, Imlib_Context> ScreenImlibContextContainer; +class ScreenImlibContextContainer : public std::map<int, Imlib_Context> { +public: + ~ScreenImlibContextContainer() { + + std::map<int, Imlib_Context>::iterator it = this->begin(); + std::map<int, Imlib_Context>::iterator it_end = this->end(); + for (; it != it_end; it++) { + imlib_context_free(it->second); + } + } +}; typedef ScreenImlibContextContainer::iterator ScreenImlibContext; ScreenImlibContextContainer contexts; - } // anon namespace

@@ -67,16 +76,6 @@ const char** format = NULL;

for(format = format_list; *format != NULL; format++) { Image::registerType(*format, *this); } -} - -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 {
M src/FbTk/ImageImlib2.hhsrc/FbTk/ImageImlib2.hh

@@ -28,7 +28,6 @@

class ImageImlib2: public ImageBase { public: ImageImlib2(); - ~ImageImlib2(); PixmapWithMask *load(const std::string &filename, int screen_num) const; };