LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   realloc , malloc and free fails at the same point (https://www.linuxquestions.org/questions/programming-9/realloc-malloc-and-free-fails-at-the-same-point-460693/)

level3 07-03-2006 06:02 PM

realloc , malloc and free fails at the same point
 
realloc , malloc and free fails at the same point and I can not why (memory corruption).

can be because I realloc a zone where I have pointers to mmaped files?

Any suggestion are wellcome.

jtshaw 07-03-2006 07:34 PM

It would be helpful to see the code to tell you for sure... however, are you trying to realloc a pointer that was mmapped? I'm not so sure that is a wonderful idea.

level3 07-04-2006 03:57 AM

reply
 
do not realloc pointer to mmaped, realloc zone of pointer to mmaped zone.

like this:


typedef struct Pointer_to_mmaped
{
void *pointer_to_disk;
};

struct Pointer_to_mmaped *pointer_to_mmaped;

pointer_to_mmaped = (struct Pointer_to_mmaped *) malloc (size);

pointer_to_mmaped = realloc (pointer_to_mmaped,size);

jlliagre 07-04-2006 06:09 AM

I would use a toll like valgrind to find out why the memory is corrupted.

sundialsvcs 07-04-2006 11:51 AM

If it's memory-mapped storage, as in "a window to a portion of a disk file," then it does not make logical sense to malloc() it. Apples and oranges.

Anyway, what you did was "you hosed the stack somehow." Maybe it was a double-free, for instance, or you freed memory that had never been allocated.

"Mixing memory-mapped stuff and malloc?" :jawa: That would do it...


All times are GMT -5. The time now is 12:06 AM.