This is a gift for
pukupukudragon of their character Daemon!
When writing code, it is very important to always be on the lookout for potential memory leaks! You wouldn't want that to happen....
pukupukudragon of their character Daemon!When writing code, it is very important to always be on the lookout for potential memory leaks! You wouldn't want that to happen....
Category Artwork (Digital) / Inflation
Species Daemon
Size 1280 x 960px
File Size 87.3 kB
I wish I understood C better so I could understand why this is a memory leak ;w;
Well, like... a bad one at least. As far as I understand, the bug in this code is that the for loop re-uses meal_ptr for a bunch of *different* mallocs (memory blocks of size sizeof(MEAL)), but then it only frees meal_ptr *after* the for loop, meaning that only one of the blocks actually gets freed... but it doesn't seem like this would be that much of a problem unless this whole snippet runs multiple times in the program. Because if it only runs once, it's just a chunk of memory being wasted (though maybe this could be bad if sizeof(MEAL) is really large) and not a continuous memory leak...
Or maybe I just misunderstand entirely >w<
Well, like... a bad one at least. As far as I understand, the bug in this code is that the for loop re-uses meal_ptr for a bunch of *different* mallocs (memory blocks of size sizeof(MEAL)), but then it only frees meal_ptr *after* the for loop, meaning that only one of the blocks actually gets freed... but it doesn't seem like this would be that much of a problem unless this whole snippet runs multiple times in the program. Because if it only runs once, it's just a chunk of memory being wasted (though maybe this could be bad if sizeof(MEAL) is really large) and not a continuous memory leak...
Or maybe I just misunderstand entirely >w<
FA+

Comments