Menu

#304 threadCleanup does not check for 0-pointer

v1.1.3
closed
5
2016-03-22
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 Haisman

    Václav Haisman - 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 Haisman

    Václav Haisman - 2014-05-13
    • labels: --> cleanup, threads
     
  • Václav Haisman

    Václav Haisman - 2016-03-22
    • status: open --> closed
     

Log in to post a comment.