Ranter
Join devRant
Do all the things like
				++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
				Sign Up
			Pipeless API
 
				From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
				Learn More
			Comments
		
- 
				
				 BigBoo22677y@electric-ghost I'm trying to figure out why, according to this flowchart, it's legal to do. BigBoo22677y@electric-ghost I'm trying to figure out why, according to this flowchart, it's legal to do.
 
 free(a);
 free(b);
 free(a);
 
 But not
 
 free(a);
 free(a);
 
 I know that it works this way, but can't find out why.
- 
				
				 BigBoo22677y@GMR516 I'm a rebel. BigBoo22677y@GMR516 I'm a rebel.
 
 Was pretty sure I removed the first tag. But I'm willing to roll with being ambiguous.
- 
				
				 aritzh7337y@BigBoo neither of them should work, should they? You "should" get a double free error on both. At least if a != 0 anyway aritzh7337y@BigBoo neither of them should work, should they? You "should" get a double free error on both. At least if a != 0 anyway
- 
				
				 aritzh7337y@BigBoo wow. It actually does. But it only happens for small mallocs (in my tests, sizeof(int)*30 or smaller), while for bigger allocations, both give a double free error. So many bugs will be hidden because of this... aritzh7337y@BigBoo wow. It actually does. But it only happens for small mallocs (in my tests, sizeof(int)*30 or smaller), while for bigger allocations, both give a double free error. So many bugs will be hidden because of this...
- 
				
				 BigBoo22677y@aritzh There's a lot of flaws with memory allocation in C. Which also can lead to security issues if not handled properly. BigBoo22677y@aritzh There's a lot of flaws with memory allocation in C. Which also can lead to security issues if not handled properly.
 
 It's all a bit complicated. But very interesting to deep dive into.
Related Rants
- 
						
							 aayusharyan10Why do people (Some devs too...) bloody hell think that devs have Hard time fixing the Semi Colon issue, we ha... aayusharyan10Why do people (Some devs too...) bloody hell think that devs have Hard time fixing the Semi Colon issue, we ha...
- 
						
							 AlgoRythm12Military grade encryption: md5 Enterprise grade encryption: Base64 AlgoRythm12Military grade encryption: md5 Enterprise grade encryption: Base64
- 
						
							 boombodies10Dev: Why do you have an identical if statement right below this one? Manager: Because I want the code to doub... boombodies10Dev: Why do you have an identical if statement right below this one? Manager: Because I want the code to doub...



How malloc works? It's easy. Just follow this simple flowchart and you will understand in no time.
joke/meme
not a joke