Bug 1095366 - double free or corruption with multiple log4c_init and log4c_fini
Summary: double free or corruption with multiple log4c_init and log4c_fini
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: log4c
Version: 20
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: František Dvořák
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-05-07 14:42 UTC by Daniele Branchini
Modified: 2014-05-21 02:35 UTC (History)
1 user (show)

Fixed In Version: log4c-1.2.4-2.fc20
Clone Of:
Environment:
Last Closed: 2014-05-21 02:28:52 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
cpp source triggering the bug (256 bytes, text/x-c++src)
2014-05-07 14:45 UTC, Daniele Branchini
no flags Details

Description Daniele Branchini 2014-05-07 14:42:55 UTC
Description of problem:
multiple log4c_init and log4c_fini in the same program generate a "double free or corruption error"

Version-Release number of selected component (if applicable):
log4c-devel-1.2.4-1.fc20.x86_64
gcc-c++-4.8.2-7.fc20.x86_64


How reproducible:
by compiling and running attached bad-log4c.cpp

Steps to Reproduce:
1. download the attachment
2. compile it with:
g++ `log4c-config  --cflags --libs` bad-log4c.cpp
3. run the resulting a.out


Actual results:
$ ./a.out 
*** Error in `./a.out': double free or corruption (!prev): 0x0000000001f96040 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3ece475cff]
/lib64/libc.so.6[0x3ece47cff8]
/lib64/liblog4c.so.3(sd_hash_lookadd+0x16d)[0x35f260b18d]
/lib64/liblog4c.so.3(log4c_layout_type_set+0x21)[0x35f26087b1]
/lib64/liblog4c.so.3(log4c_init+0x5c)[0x35f260703c]
./a.out[0x400713]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x3ece421d65]
./a.out[0x400639]


Expected results:
no errors

Additional info:

Comment 1 Daniele Branchini 2014-05-07 14:45:13 UTC
Created attachment 893311 [details]
cpp source triggering the bug

Comment 2 František Dvořák 2014-05-07 15:28:10 UTC
Thanks for the report.

The problem is with the usage of local static variables, in this case in layout.c (although the similar approach is used on more places there):

static sd_hash_t* log4c_layout_types(void)
{
    static sd_hash_t* types = NULL;

    if (!types)
        types = sd_hash_new(20, NULL);

    return types;
}

extern void log4c_layout_types_free( void ) {
        sd_hash_t * types = log4c_layout_types();
        if ( types != NULL ) {
                sd_hash_delete( types );
        }
}

Comment 3 Fedora Update System 2014-05-08 20:13:12 UTC
log4c-1.2.4-2.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/log4c-1.2.4-2.fc20

Comment 4 Fedora Update System 2014-05-08 20:14:02 UTC
log4c-1.2.4-2.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/log4c-1.2.4-2.fc19

Comment 5 Fedora Update System 2014-05-09 02:56:23 UTC
Package log4c-1.2.4-2.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing log4c-1.2.4-2.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-6149/log4c-1.2.4-2.fc20
then log in and leave karma (feedback).

Comment 6 Daniele Branchini 2014-05-09 07:53:50 UTC
Thank you very much for the quick response.

I just updated log4c and log4c-devel 1.2.4-2.fc20 from the testing repository, the attached source seems to be working now

$ g++ `log4c-config  --cflags --libs` bad-log4c.cpp
$ ./a.out 
$ echo $?
0

Comment 7 Fedora Update System 2014-05-21 02:28:52 UTC
log4c-1.2.4-2.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Fedora Update System 2014-05-21 02:35:18 UTC
log4c-1.2.4-2.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.