A problem with realloc

A problem with realloc

Post by Jason Howa » Fri, 07 Jul 2000 04:00:00



        I'm having a problem with realloc, or one of the functions
that it calls. I'm using qnx 4.22 and my process is using a flat
memory model. A number of dynamic arrays are used and realloc works
fine up to a point.  I end up getting a Segmentation Violation error.
For parameters I am passing it an adress that it has used before in
the same session.

        Using the watcom de* wvideo and the show calls command,
the function calls go like this:
MyFunction
        |
        V
_nrealloc
        |
        V
_nexpand
        |
        V
_ExpandDGROUP   -> access Violation

If anyone knows what is happening to cause this error please let me
know. Thanks,

                Jason Howard

 
 
 

A problem with realloc

Post by Mario Chares » Sat, 08 Jul 2000 04:00:00


4.22 is rather old...  I'm not aware of any bug regarding realloc.
I would guess your program is trashing some memory area.

Unfortunately it's very hard to track those type of problem.
I will try to post on my web site some replacement routine
for memory function that help debug those type of problem
(assuming it is your problem)

When I'll post it I'll send you an email with the link if your
interested?


Quote:> I'm having a problem with realloc, or one of the functions
> that it calls. I'm using qnx 4.22 and my process is using a flat
> memory model. A number of dynamic arrays are used and realloc works
> fine up to a point.  I end up getting a Segmentation Violation error.
> For parameters I am passing it an adress that it has used before in
> the same session.

> Using the watcom de* wvideo and the show calls command,
> the function calls go like this:
> MyFunction
> |
> V
> _nrealloc
> |
> V
> _nexpand
> |
> V
> _ExpandDGROUP -> access Violation

> If anyone knows what is happening to cause this error please let me
> know. Thanks,

> Jason Howard


 
 
 

1. realloc problem

Yes, you messed up.  realloc returns a pointer to the revised
buffer.  If that is non-NULL it succeeded, and you can copy that
result into work_buffer.  If it is NULL, realloc failed and
work_buffer is unchanged.  So you need something like:

    void *tmp;
    ....

    if (NULL == (tmp = realloc(wkbuff, whatever))) {
       /* take corrective action, wkbuff is unaltered */
    }
    else {
       /* wkbuff is now valueless, do NOT free/dereference it */
       wkbuff = tmp;
       /* use wkbuff, it has grown/shrunk etc. */
    }

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)

2. IF THEN STATEMENT

3. about realloc memo in TornadoII

4. Review of Features?

5. Memory allocation and realloc

6. Epson Stylus Color 500

7. Memory fragmentation with realloc()

8. realloc bug in MSL?

9. realloc down

10. realloc freed memory

11. Epox (Aralion) ATA100 RAID card problems, problems, problems

12. Problems, problems and more problems