TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Neil Heller
from: Jasen Betts
date: 2003-05-28 18:15:24
subject: FREEing a pointer to a p

Hi Neil.

26-May-03 11:58:02, Neil Heller wrote to Jasen Betts


 NH>> Now, after I've used the variables in various (nefarious) ways, I
 NH>> need to free them.  However, if I go

 NH>> free(pbar1->next->charvar);

 JB>> if it doesn't throw the assertion if you free them immediately
 JB>> after initialising them the eror must lie in the nefarious code.

 JB>> Also you should check that each malloc succeeds.

 NH> It turned out that I was malloc(ing) strlen(foo) instead of
 NH> strlen(foo)+1.

ah... maybe that's why strdup was invented.

 NH> What really troubles me is why an assert was thrown when I attempted
 NH> to free() the first node of the linked list.

C doesn't do range checking... when you write to an unallocated area the
results are unpredictable.

 -=> Bye <=-

---
* Origin: I smell a rat. Did you bake it or fry it? (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.