#: 19522 S12/OS9/68000 (OSK)
23-Dec-93 19:55:39
Sb: C problems
Fm: Bob van der Poel 76510,2203
To: All
I think I may have found a bug in the 2.3 C realloc() function. What appears to
happen is:
If realloc() fails (ie. returns a NULL ptr) it appears that the original memory
passed is freed! I have some code which looks something like this:
newbuf=realloc(bufstart, memreq);
if(!newbuf) ... report no more room error and restart....
if(newbuf!=bufstart) ...set 'bufstart' etc to newbuf values if buffer moved
However, using SSM any access to memory in the original buffer generates a bus
error. I have verified this with srcdbg.
I have avoided the problem by not using realloc(). Instead I always allocate a
completely new buffer and then copy the old buffer to the new one and free()
the old one. This works...but is wasteful if the original could have been
expanded as realloc() does.
Anyone else had a similar problem?
|