home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!news.cs.indiana.edu!noose.ecn.purdue.edu!ecn.purdue.edu!kudva
- From: kudva@ecn.purdue.edu (Gautham K. Kudva)
- Subject: Signal Handlers and malloc()
- Message-ID: <1992Nov9.064910.778@noose.ecn.purdue.edu>
- Followup-To: comp.unix.programmer
- Sender: news@noose.ecn.purdue.edu (USENET news)
- Organization: Purdue University Engineering Computer Network
- Date: Mon, 9 Nov 1992 06:49:10 GMT
- Lines: 36
-
-
- Hi netters,
- I've come across a problem with signal handlers that has me completely
- stumped. I'm hoping that someone will be able to help me on this. The
- environment I'm using is SunOS 4.1 on a Sparc IPC, but I expect that this
- would be a problem on any Unix platform.
-
- I've written a signal handler for the VTALRM signal. The signal
- handler calls another routine which does quite a bit of work. This program
- start crashing in an unpredictable fashion. On using purify, it gave me the
- following error (that software is simply awesome!!):
-
- Warning: calling malloc(16) while in a call
- to malloc/free/memalign. Probably from a signal handler.
- malloc/free/memalign are *not* reentrant and this may
- cause a later segv.
-
- I have some malloc calls within the routine called by the signal handler,
- and apparently the signal handler was invoked by interrupting a malloc
- call. Did some reading and sure enough, Rich Stevens' excellent book
- "Advanced programming in the UNIX environment" warns of exactly this
- problem. Now my question is - "Is there a fix?". I could coneivably guard
- all my malloc/free calls with sigblocks... but I'm writing something that
- will be used by other people. There's no way I can be sure that everyone
- else will also guard their malloc/free calls. Besides, there may be other
- routines that are non-reentrant in this fashion. I guess what I'm looking
- for is a library of reentrant or guarded versions of the standard
- non-reentrant calls. With the diverse uses to which signals have been put
- over the years, surely something like this exists? Public domain versions
- would be great, but commercial ones are ok too.
-
- Please post or e-mail. I will summarize.
-
- Thanks much in advance,
- Gautham Kudva
- kudva@ecn.purdue.edu
-