| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | free() |
Hi Frank FA> I also believe that in a multitask environment, that would be FA> fatal if another program got a slice between free() and return, PC> not sure if i understand what you mean here?. FA> Well i imagined a scenario, where Prog1 is running in conjunction FA> with Prog2, Prog1 goes off and does it's thing in foo() and just as it FA> executed the free(str) statement, OS steps in and gives Prog2 a slice FA> Prog2 happens to be looking for memory and comes across a "free" block FA> where Prog1's str lives, and happily populates it... FA> When Prog1 gets it's slice back it goes and returns ptr which is no FA> longer the same animal, ptr is the same, it's just the block of memory that it points to that may have changed. And since your code has already freed that block, you shouldn't expect its contents to be still valid. For example, you might have a function call between the free() and the return that might call an alloc type function. Or an interrupt routine could pop its head up just then and do the same. FA> I also believe that in a multitask environment, that would be FA> fatal if another program got a slice between free() and return, Nothing actually wrong with returning ptr after it's been freed, it's just pointless. Unless it's used to return an error if something in the function failed (a bit obfuscated for my taste, unless fully commented...) Cheers --- PPoint 1.88* Origin: Silicon Heaven (3:711/934.16) SEEN-BY: 711/808 934 @PATH: 711/934 |
|
| 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™.