malloc mutex and exceptions

Dave Korn dk@artimi.com
Mon Mar 22 16:32:00 GMT 2004


> -----Original Message-----
> From: gcc-owner On Behalf Of Ignasi Villagrasa
> Sent: 21 March 2004 19:31

> Hi everyone,
> 
> I have been migrating to gcc a server C/C++ based software 
> and I' like to control SIGSEGV signal exceptions. So I use 
> sigaction and the corresponding handlers to accomplish this target. 
> 
> The problem arises when a SIGSEGV happens inside a new 
> operator. 

  Fix the bug in your program that trashes the heap.  SEGV inside the malloc
handler is basically not a recoverable situation.

> I have many users connected to the program and the 
> clients suddenly hang.  That's because of pthread mutex the 
> malloc and free routines use. The SIGSEGV occurs after 
> pthread_mutex_lock call and before pthread_mutex_unlock. 

  Fix the bug in your program that trashes the heap.

> So, every time a user tries to use this semaphore the program 
> hangs. 

  Fix the bug in your program that trashes the heap.

> New and delete uses malloc and free with reentrant 
> features. And I'm interested in that because of pthread 
> program use, but I have this problem for the exception control.
> 
> When I have a problem using one of my mutex I can control 
> lock and unlock properly, but new and delete mutex relies on 
> library variables.
> 
> Is there any way I can control this internal mutex ?

  By not trashing the heap, the new and delete handlers will complete
successfully instead of crashing and get a chance to release the mutex.

> Is there any compiler option to change this behaviour ?

  Unfortunately there's no "-fcorrect-stray-pointer-bugs".  You'll just have
to fix your bug.



    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc mailing list