MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/x2lbsc/malloc_and_free_are_a_bad_api/imtg2cb/?context=3
r/cpp • u/iprogshine • Aug 31 '22
90 comments sorted by
View all comments
-2
At least when programming in C, I wish that free() would null the free'd pointer. That's a common problem I see people doing (freeing and forgetting to null leading to a potential use after free)
4 u/matthieum Sep 01 '22 Honestly, I've never seen the appeal.Pointers are freely copied anyway, nulling one copy won't save you from accidentally using any of the myriad others floating around. 5 u/evaned Sep 01 '22 Help doesn't have to be perfect to be helpful. 2 u/matthieum Sep 02 '22 Certainly, but we must be careful about not inducing a false sense of security either, otherwise it's more harmful than helpful.
4
Honestly, I've never seen the appeal.
Pointers are freely copied anyway, nulling one copy won't save you from accidentally using any of the myriad others floating around.
5 u/evaned Sep 01 '22 Help doesn't have to be perfect to be helpful. 2 u/matthieum Sep 02 '22 Certainly, but we must be careful about not inducing a false sense of security either, otherwise it's more harmful than helpful.
5
Help doesn't have to be perfect to be helpful.
2 u/matthieum Sep 02 '22 Certainly, but we must be careful about not inducing a false sense of security either, otherwise it's more harmful than helpful.
2
Certainly, but we must be careful about not inducing a false sense of security either, otherwise it's more harmful than helpful.
-2
u/t3chfreek Sep 01 '22
At least when programming in C, I wish that free() would null the free'd pointer. That's a common problem I see people doing (freeing and forgetting to null leading to a potential use after free)