[Webkit-unassigned] [Bug 121407] [Windows] Embedding in ASP.NET (and other) contexts cause crash on thread termination

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Sep 16 00:12:29 PDT 2013


https://bugs.webkit.org/show_bug.cgi?id=121407





--- Comment #2 from Vincent Van Den Berghe <Vincent.VanDenBerghe at bvdinfo.com>  2013-09-16 00:11:38 PST ---
Far from me to be pedantic, but DEFINE_STATIC_LOCAL avoids calling destructors in exchange for leaking memory. This means that applications will be able to call CoFreeUnusedLibraries(), but the leaks will remain. Leaking memory in a DLL is bad. If it can be avoided, it should.

Here's a thought: we want to avoid static objects to have their destructor called. If we know that no calling destructors will not leak additional memory, the only leak will be from DEFINE_STATIC_LOCAL, according to the current implementation:

#define DEFINE_STATIC_LOCAL(type, name, arguments) \
    static type& name = *new type arguments

So why not change it to one of those:

// if the compiler supports C++11, you can use this:
#define DEFINE_STATIC_LOCAL(type, name, arguments) \
  static std::unique_ptr<char[]> name##Ptr(new char[sizeof(type)]); \
  static type& name = *new (name##Ptr.get())type arguments

// if the compiler doesn't support C++x11, you can rely on ISO 14882 2nd ed section 23.2.4
// regarding the contiguous storage of vectors
#define DEFINE_STATIC_LOCAL(type, name, arguments) \
  static std::vector<char> name##Ptr(sizeof(type)); \
  static type& name = *new (&name##Ptr[0])type arguments

This would have the benefit of cleaning up the actual memory of the object when the DLL is unloaded, but without calling the useless destructor. The best of both worlds!

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list