Boost logo

Boost :

Subject: [boost] [locale] Memory leaks?
From: Jookia (166291_at_[hidden])
Date: 2013-03-03 15:19:59


Hello!

I've been debugging my application that uses Boost.Locale for the past
five hours or so, and I've found it curious that it leaks memory.

In order to stop it, I have to do a couple of weird things, such as
including ICU in to my projects and calling u_cleanup at the end of my
application. I also have to disable certain facets. I've put all this
together in some source code, that by default won't leak, but
uncommenting various parts will cause it to leak:

// ---- BEGIN CODE ----------------------------------------------------

#include <boost/locale.hpp>
#include <unicode/uclean.h>
#include <iostream>

using namespace boost::locale;
using namespace std;

int main()
{
   generator gen;
   gen.categories(
     convert_facet |
     //collation_facet | // Various errors.
     //formatting_facet | // Various errors.
     //parsing_facet | // Various errors.
     message_facet |
     //codepage_facet | // Various errors.
     boundary_facet |
     calendar_facet |
     information_facet);

   locale newLoc = gen("zh_CN.GB18030");

   locale::global(newLoc);
   cout.imbue(newLoc);

   // ios_info::get doesn't clean up after itself.
   //cout << as::date << time(0) << endl;

   // Do this at the end of the program to clean up resources.
   locale::global(std::locale("C"));
   cout.imbue(std::locale("C"));
   u_cleanup();
}

// ---- END CODE ------------------------------------------------------

Dumping this as 'hello.cpp' and running this is how I'm debugging it:

g++ hello.cpp -lboost_locale -licuuc && valgrind --leak-check=full
--show-reachable=yes ./a.out

Thanks,
Jookia.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk