[comp.sys.amiga.programmer] Problems with SAS/C 'malloc'

baker@wbc.enet.dec.com (03/19/91)

-Message-Text-Follows-

	This weekend, I ran into a problem with malloc().  I'm
	using SAS/C 5.10 (*not* 5.10a) running under AmigaDOS 1.3.2
	on a B2000 with a GVP accelerator and 5 megs of memory.

	The symptom: When I call malloc() with a request that's larger
	than the current available space (as indicated by sizmem()),
	it calls getmeml() to add more space to the heap, and getmemll()
	GURU's the system.  I used CPR to trace the problem into getmeml(),
	but I haven't spent enough time looking at getmeml() to figure out
	why it's dying.  The problem is *not* lack of memory; at the time
	of each crash, there's better than 4 megs of available space...

	The program I'm working on is large and rather complex, and the
	problem doesn't show up until a number of malloc()'s have been
	done succesfully.   However, the bug appears reliably (i.e.,
	every time).  Unfortunately,  small sample programs with excerpts
	from the dying code don't seem to exhibit the problem.

	Question:  Are there any known/documented problems with the SAS/C
	memory allocator ?  If so, does the 5.10a patch correct them ?  If
	not, is there a clean workaround ?  Thanks.

	Art Baker
	<insert usual disclaimers here>

jap@convex.cl.msu.edu (Joe Porkka) (03/21/91)

baker@wbc.enet.dec.com writes:

>-Message-Text-Follows-

>	This weekend, I ran into a problem with malloc().  I'm
>	using SAS/C 5.10 (*not* 5.10a) running under AmigaDOS 1.3.2
>	on a B2000 with a GVP accelerator and 5 megs of memory.

>	The symptom: When I call malloc() with a request that's larger
>	than the current available space (as indicated by sizmem()),
>	it calls getmeml() to add more space to the heap, and getmemll()
>	GURU's the system.  I used CPR to trace the problem into getmeml(),

>	The program I'm working on is large and rather complex, and the
				      ^^^^^^^^^^^^^^^^^^^^^^^^

Most likely your program is a fault - it is tromping on
memory that it ought not.

Perhaps you over (or under) step a malloced array, thusly trashing
the booking info malloc keeps at the head of each malloced
block?

Or, you simply have a wild pointer that gets reliably pointed
at the wrong location.