[Info-vax] calloc fails with access violation

Steven Schweda sms.antinode at gmail.com
Tue Aug 25 01:35:42 EDT 2009


Jose Cuevas wrote:

> We are getting an access violation (a crash) on calls to
> calloc() [...]

   This is not a very useful description of the actual
failure.  Did I miss something, or have we not been shown an
actual traceback?

   If calloc() (or malloc(), or realloc(), ...) fails with an
ACCVIO, it may be because some code far away from the Xalloc()
call has written over some part of the heap where it shouldn't
have.  It's not unusual to do several Xalloc() operations,
then corrupt the heap by overrunning the buffer allocated by
one of them, and then have some later Xalloc() operation blow
up when it tries to deal with the corrupted heap.

   There exist many debug-malloc libraries which attempt to
catch problems like this.  I don't use them enough to
recommend one, however.

> I guess it was too much to expect it to be as simple as
> needing strlen +1.

   I doubt that any Xalloc() implementation allocates only 13
bytes if you ask it to allocate 13 bytes.  Knowing nothing,
I'd guess that you'd get at least about 512 bytes, no matter
what you request.  Truly effective heap corruption probably
needs a bigger problem than an off-by-one error.



More information about the Info-vax mailing list