* Re: realloc
2002-08-05 20:35 realloc Chuck Winters
@ 2002-08-05 18:26 ` Mehran Rezaei
2002-08-05 21:26 ` realloc Glynn Clements
2002-08-05 21:46 ` realloc Jason P. Winters
2 siblings, 0 replies; 4+ messages in thread
From: Mehran Rezaei @ 2002-08-05 18:26 UTC (permalink / raw)
To: Chuck Winters; +Cc: linux-c-programming
Chuck Winters wrote:
> Hello all,
> Anyone know why a program would freeze at realloc? I thought
> if there was a problem, realloc would just fail.
>
> Thanks,
> Chuck
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
The problem happens just because of specific allocator that you are using. You can
avoid it by simply malloc new area, copy the content and free previos one. Just as
follow:
#include <sys/mman.h>
ptr1=malloc(size1);
.
.
.
ptr2=realloc(ptr1,size2);
...........................
ptr1=malloc(size1);
.
.
.
ptr2=malloc(size2);
memcpy(ptr2,ptr1,size1);
free(ptr1);
Good Luck,
Mehran
^ permalink raw reply [flat|nested] 4+ messages in thread
* realloc
@ 2002-08-05 20:35 Chuck Winters
2002-08-05 18:26 ` realloc Mehran Rezaei
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chuck Winters @ 2002-08-05 20:35 UTC (permalink / raw)
To: linux-c-programming
Hello all,
Anyone know why a program would freeze at realloc? I thought
if there was a problem, realloc would just fail.
Thanks,
Chuck
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: realloc
2002-08-05 20:35 realloc Chuck Winters
2002-08-05 18:26 ` realloc Mehran Rezaei
@ 2002-08-05 21:26 ` Glynn Clements
2002-08-05 21:46 ` realloc Jason P. Winters
2 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2002-08-05 21:26 UTC (permalink / raw)
To: Chuck Winters; +Cc: linux-c-programming
Chuck Winters wrote:
> Anyone know why a program would freeze at realloc?
By far the most likely reasons are:
a) heap corruption, and
b) passing an invalid pointer (one which wasn't returned from malloc
(or similar), or which has since been freed.
> I thought if there was a problem, realloc would just fail.
If there is insufficient memory to satisfy a request, realloc would
fail.
OTOH, if the heap is corrupt, or if the pointer is invalid, all bets
are off; calling malloc/calloc/realloc/free etc will result in
"undefined behaviour".
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: realloc
2002-08-05 20:35 realloc Chuck Winters
2002-08-05 18:26 ` realloc Mehran Rezaei
2002-08-05 21:26 ` realloc Glynn Clements
@ 2002-08-05 21:46 ` Jason P. Winters
2 siblings, 0 replies; 4+ messages in thread
From: Jason P. Winters @ 2002-08-05 21:46 UTC (permalink / raw)
To: Chuck Winters; +Cc: linux-c-programming
> Hello all,
> Anyone know why a program would freeze at realloc? I thought
> if there was a problem, realloc would just fail.
Not really. I've had that problem... it's a corrupted heap problem,
usually. And the results are undefined.. :(
Ciao!
Jason
--
|UUCP jason@txt.com Who wills, Can.
|VOICE (408) 243-3425 Who tries, Does.
|LOCAL Hey, Jason! Who loves, Lives. o_.
|Disclaimer: Not me! I didn't do *THAT!* <|
|Local Disclaimer: I'm not here! A. McCaffrey 4
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-05 21:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-05 20:35 realloc Chuck Winters
2002-08-05 18:26 ` realloc Mehran Rezaei
2002-08-05 21:26 ` realloc Glynn Clements
2002-08-05 21:46 ` realloc Jason P. Winters
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).