Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#11 Protect malloc/calloc/free agains reentrant calls (Cygwin)

open
h_ayguen
None
5
2008-08-04
2008-02-05
Jesper Rasmussen
No

I had lots of problems tracking down a memory bug that turned out to be caused by the Cygwin/DUMA heap being corrupted by multiple threads making calls to malloc/free.

DUMA reported all sorts of strange segfaults inside it self.

It would be very nice if DUMA's memory functions had guards against reentrancy.

Discussion

  • h_ayguen
    h_ayguen
    2008-02-06

    • priority: 5 --> 9
     
  • h_ayguen
    h_ayguen
    2008-02-06

    Logged In: YES
    user_id=1354765
    Originator: NO

    hello jesper,

    please be some patient and do not open further feature requests!
    if yor are right .. this is a real bug an d i'll fix as soon as possible.
    but for now i'm lying ill in my bed.
    meanwhile you might try donating a test program like testmt.c?!

    regards

    Hayati Ayguen

     
  • example

     
    Attachments
  • Logged In: YES
    user_id=1990438
    Originator: YES

    Hi Hayati,

    First of all, thank you very much for a great program. DUMA is the best thing that has happened to Cygwin development in years! I haven't found any other memory debugger that works with Cygwin.

    I've attached a small test program that creates this problem using SDL to do the threads.

    When I run the resulting program on my box I get all sorts of random errors.

    Cheers,
    Jesper

    ps. Sorry for the multiple feature request, it was my browser that did it, not me :o)
    pps. Get well soon.

    File Added: sdltest.c

     
  • h_ayguen
    h_ayguen
    2008-02-07

    Logged In: YES
    user_id=1354765
    Originator: NO

    Just had a look at
    http://msdn2.microsoft.com/en-us/library/ms682438\(VS.85).aspx
    describing CreateSemaphore().

    Could you try again, after changing sem_inc.c line 177 from
    semHandle = CreateSemaphore( &semSecAttr /* pointer to security attributes */
    , 1 /* initial count */
    , 10 /* maximum count */
    , semLocalName /* pointer to semaphore-object name */
    );
    to
    semHandle = CreateSemaphore( &semSecAttr /* pointer to security attributes */
    , 1 /* initial count */
    , 1 /* maximum count */
    , semLocalName /* pointer to semaphore-object name */
    );

    please report if this solves the problem. why the hell is maximum count set to 10???

    ps: i've not a development environment on my notebook :-(

     
  • h_ayguen
    h_ayguen
    2008-03-10

    • assigned_to: nobody --> h_ayguen
     
  • h_ayguen
    h_ayguen
    2008-03-10

    Logged In: YES
    user_id=1354765
    Originator: NO

    Hello Jesper,

    would you please add

    #include "duma.h"

    and add following
    #ifdef DUMA_EXPLICIT_INIT
    duma_init();
    #endif

    at begin of your main() in sdltest.c

    and report if the error is gone.

    regards

    Hayati

     
  • Logged In: YES
    user_id=1990438
    Originator: YES

    Hi Hayati,

    Changing the arguments to CreateSemaphore in sem_inc.c didn't change the behavior of DUMA.

    But, adding the duma_init() call solved the problem! I guess that somehow the problem was that the semaphores wasn't initialized (?)

    It seems like it was all my fault - sorry for that.

    Two suggestions:
    - It would be nice if DUMA could check if it wasn't been properly initialized.
    - The documentation should be more clear on this point.

    Cheers,
    Jesper

     
  • h_ayguen
    h_ayguen
    2008-08-04

    • priority: 9 --> 5
     
  • h_ayguen
    h_ayguen
    2008-08-04

    Logged In: YES
    user_id=1354765
    Originator: NO

    Hi Jesper,

    in CVS i've enhanced the threading test testmt.c to run on Windows.
    And there i also need to call duma_init().
    Directly printing in first allocation produces other problems!
    A check is easy and already done .. but how to know that the critcal (pthread initialization) part is over and duma shall get fully initialized?

    Thus we only have the documentation aspect! Any idea where to document?

    regards

    Hayati