-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Description:
We’ve identified a potential memory management issue in the current implementation of the game. Specifically, there are areas where dynamically allocated memory may not be freed correctly, leading to memory leaks. This can result in increased memory usage and potential crashes during extended gameplDescription:
We’ve identified a potential memory management issue in the current implementation of the game. Specifically, there are areas where dynamically allocated memory may not be freed correctly, leading to memory leaks. This can result in increased memory usage and potential crashes during extended gameplay sessions.
Steps to Reproduce:
Run the game and play for an extended period, spawning and interacting with multiple zombies, bullets, and platforms.
Observe the memory usage over time, noting any increase.
Expected Behavior:
The game should manage memory efficiently, releasing unused resources properly to maintain stable memory usage throughout gameplay.
Actual Behavior:
Memory usage increases over time, indicating that not all dynamically allocated memory is being freed properly.
Examples and Code Snippets:
Below are examples of areas in the code where dynamic memory allocation occurs but may not be properly freed:ay sessions.
`// Example of memory allocation for bullets
Bullet *newBullets = realloc(bullets, (bulletCount + 1) * sizeof(Bullet));
if (newBullets == NULL) {
printf("Memory allocation failed!\n");
game_is_running = false;
return;
}
bullets = newBullets;
// Ensure bullets are freed in DestroyWindowInternal
void DestroyWindowInternal(void){
free(bullets);
bullets = NULL;
...
}
// Example of memory allocation for zombies
zombies = realloc(zombies, sizeof(Zombie) * (numberOfZombies + zombieCount));
if (zombies == NULL) {
printf("Memory allocation failed!\n");
game_is_running = false;
return;
}
// Ensure zombies are freed in DestroyWindowInternal
void DestroyWindowInternal(void){
free(zombies);
zombies = NULL;
...
}`