Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#304 threadCleanup does not check for 0-pointer

v1.1.3
open
Václav Zeman
5
2014-05-13
2014-05-13
No

I've encountered a bug in combination with dynamically loaded libraries. Through some unavoidable things, log4cplus::Logger::getRoot().shutdown(); is called twice.
However, the per-thread data is released the first time, and get_ptd(false) in threadCleanup does not allocate a new one, so a 0-pointer is returned. So, a check if(ptd) is missing before the delete ptd.

From global-init.cxx

void
threadCleanup ()
{
    // Do thread-specific cleanup.
    internal::per_thread_data * ptd = internal::get_ptd (false);
    delete ptd;
    internal::set_ptd (0);
}

Should be something like:

void
threadCleanup ()
{
    // Do thread-specific cleanup.
    internal::per_thread_data * ptd = internal::get_ptd (false);
    if(ptd)
        delete ptd;
    internal::set_ptd (0);
}

Discussion

  • Václav Zeman
    Václav Zeman
    2014-05-13

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,5 +1,5 @@
    -I've encountered a bug in combination with dynamically loaded libraries. Through some unavoidable things, log4cplus::Logger::getRoot().shutdown(); is called twice.
    -However, the per-thread data is released the first time, and get_ptd(false) in threadCleanup does not allocate a new one, so a 0-pointer is returned. So, a check if(ptd) is missing before the delete ptd.
    +I've encountered a bug in combination with dynamically loaded libraries. Through some unavoidable things, `log4cplus::Logger::getRoot().shutdown();` is called twice.
    +However, the per-thread data is released the first time, and `get_ptd(false)` in `threadCleanup` does not allocate a new one, so a 0-pointer is returned. So, a check `if(ptd)` is missing before the `delete ptd`.
    
     From global-init.cxx
    
    • assigned_to: Václav Zeman
     
  • Václav Zeman
    Václav Zeman
    2014-05-13

    • labels: --> cleanup, threads