Opened 10 years ago

Last modified 10 years ago

#7211 new Bugs

path_locale destructor crashes when overloaded operator new and delete are present

Reported by: Michel Lemay <flaming_mike_@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.51.0 Severity: Problem
Keywords: Cc:

Description

path_locale is defined using this construct in path.cpp:

std::locale path_locale(std::locale(), new windows_file_codecvt);

Under the debugger of VC10/11, the destructor of std::locale calls free() for this facet pointer when refcount reaches 0.

I ackknowledge this is a bug in dinkumware implementation of the microsoft STL. See for mor information:

http://connect.microsoft.com/VisualStudio/feedback/details/750951/std-locale-implementation-in-crt-assumes-all-facets-to-be-allocated-on-crt-heap-and-crashes-in-destructor-in-debug-mode-if-a-facet-was-allocated-by-a-custom-allocator

That said, I suggest a workaround made using only standard calls.

in v3/src/windows_file_codecvt.hpp, change the constructor to pass along default refcount:

explicit windows_file_codecvt(size_t refs = 0)

: std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}

and in v3/src/path.cpp, define path_locale like this:

windows_file_codecvt windows_cvt_path_locale(1);

std::locale path_locale(std::locale(), &windows_cvt_path_locale);

Change History (1)

comment:1 by Michel Lemay <flaming_mike_@…>, 10 years ago

A quick grep in boost source code reveals other places using the same approach:

  • date-time have several uses of construct like this one:

num_put* f = new num_put();

std::locale l = std::locale(a_ios.getloc(), f);

  • icu and locales:

std::locale(in,new *_impl<*>(cd));

std::locale(tmp,new icu_formatters_cache(cd.locale));

...

Note: See TracTickets for help on using tickets.